Post History
Python 3.8+, 577 bytes (was 634 than 591 bytes before) V="eéiíaáoóuúEÉIÍAÁOÓUÚ" r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)} s=la...
Answer
#14: Post edited
# [Python 3.8+], 577 bytes- (was 634 than 591 bytes before)
- <!-- language-all: lang-python -->
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,R=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][R](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- [Try it online!][TIO-lv4qojcl]
- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
- [TIO-lv4qojcl]: https://tio.run/##jZu/bxu5Esd7/xWEimfpWRdc7poHH1xsvHFkwI4Ny3eNYRi0KFkC9AtaOYphpEiZ4ip36lKyuMqd2v3D8pbkzHCGayv3intLf74c8qOsZ6kFPH9YDmfT3/83X/z48ddBo1/aUfmPLr/Pyuf7cvO@/HZc/p2VX8/Kpz/LdWNncfDYmJS2sd9sTGaN9q@tdmNZbtzQwLAo/3FD3Wi/9SMLI8cm9yPjhuX3RaP9m8Oj26H7we3wnn6iDcz4rfVlpzgY68mt0Uq3b/f1m/v5vL9otkYDdXv16/WbUQE/6I@LvtI7pj9Qg@bn9kNrf9W@OFhcfb7@Y3VQNFdVeK@x26jmrdRo@uj37nb8RU@NeqjoaKr@Ur7Kaq@hG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IswXYbRq3InZgoAGox4eVkRJuti8AejthXSRgIxSP2LZJzVDyK39QkttswKR7x742iACoeia@MMqLN1kVgDyfl3yjYcdfCD2AuIMoBrMoyZBMUp5EVQO8UZ6IR0ODDsDavLYomp04OH844EjoxkScJdIqJLA3Y7QHSiwlvKIqgZMwETxnS5idLwV7O2TMbBkL3nD2zOUfZ8/i8lNhuwyR6zp/ZogBqnotntoxos3UR2APrld1OrVt2WbvkGAVj9@rWWiaHnXrX7PK22a33za5onN1653x5cfS6PC7Xx/n7M3SjsdDjqbyWQkueyuoh@/MQSfOUF0@KoTzPhQ8gDWrzL5aFvdEbx276xrFLbxy76RvHLr4C7CZvHCOovXHsxjeO3fSFY5e9cOym7xvri8HeL99nHzon2SE@By879APuIWJ5PQZOIpapyzRkXwolpdBVxJyxScuBuAh6/XpSmxdWTmPwkfz5LnwYu@6CfwgA8ghAG0B1IGXECkIA9YD4A2mcBUoAw4GUUW1E0YjwLL0@wcO0uxKnaUA5Q3ieBuQO1IxZySKiMzWwcKiOM/FUDRiO1YxrI0sTvPZ/FbfsF8sbPR6Hv3hT/s/jRm3V/NxWD2216Bf342VLjaaqP72f9Bd62W/6v1uDuPvf5OEm5NSB/4NC9dAipouiv1jyyAEUbatB4/Hzl7Z6fPiiiuHsfmzU3ehTXz0GXpHpbKkeaeoX1Xwc7b390mr46vPFaLpsNrLxWBX3vV6/b/qm0drZ2RkN1M3NVE/6NzdutcbNzUSPpjc3jbDjKPzj/w "Python 3.8 (pre-release) – Try It Online"
- A reference implementation, to understand the details.
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- # Python 3.8+, 577 bytes
- (was 634 than 591 bytes before)
- <!-- language-all: lang-python -->
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,R=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][R](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- [Try it online!][TIO-lv4qojcl]
- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
- [TIO-lv4qojcl]: https://tio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uHsfmzU3ehTXz0GXpHpbKkeaeoX1Xwc7b390mr46vPFaLpsNrLxWBX3vV6/b/qm0drZ2RkN1M3NVE/6NzdutcbNzUSPpjc3jbDjKPzj/w "Python 3.8 (pre-release) – Try It Online"
- A reference implementation, to understand the details.
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
#13: Post edited
# [Python 3.8 (pre-release)], 577 bytes (was 634 than 591 before)- <!-- language-all: lang-python -->
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,R=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][R](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- [Try it online!][TIO-lv4qojcl]
- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
- [TIO-lv4qojcl]: https://tio.run/##jZu/bxu5Esd7/xWEimfpWRdc7poHH1xsvHFkwI4Ny3eNYRi0KFkC9AtaOYphpEiZ4ip36lKyuMqd2v3D8pbkzHCGayv3intLf74c8qOsZ6kFPH9YDmfT3/83X/z48ddBo1/aUfmPLr/Pyuf7cvO@/HZc/p2VX8/Kpz/LdWNncfDYmJS2sd9sTGaN9q@tdmNZbtzQwLAo/3FD3Wi/9SMLI8cm9yPjhuX3RaP9m8Oj26H7we3wnn6iDcz4rfVlpzgY68mt0Uq3b/f1m/v5vL9otkYDdXv16/WbUQE/6I@LvtI7pj9Qg@bn9kNrf9W@OFhcfb7@Y3VQNFdVeK@x26jmrdRo@uj37nb8RU@NeqjoaKr@Ur7Kaq@hGlWFPxb95f1iWo2vYAur/atV25cqmo1ho71q7a2u3u5fX1@9/aVaYv@36zfj2crvb9ooeqoYqGKiirkqlo03xXw8WjZbrf/4zbDgbc8M7ibzKtO6bsNKn/ar@nufVLXfT2Jzn9r966uL6@ZDy7v2m6vW/o4azBZqoVytierdKTNVg9uhupuq@a1aGlq7SrqKfP2D6jP69XofVBfOZm@1o8K4sm1Mf2nsuf@r/nt91eztH6xgP63/Nnt7K/GP0Lr@0dNFv1AH6mqn6W@TtmroRfl96i4mu@Gy1a6gu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sdDjqbyWQkueyuoh@/MQSfOUF0@KoTzPhQ8gDWrzL5aFvdEbx276xrFLbxy76RvHLr4C7CZvHCOovXHsxjeO3fSFY5e9cOym7xvri8HeL99nHzon2SE@By879APuIWJ5PQZOIpapyzRkXwolpdBVxJyxScuBuAh6/XpSmxdWTmPwkfz5LnwYu@6CfwgA8ghAG0B1IGXECkIA9YD4A2mcBUoAw4GUUW1E0YjwLL0@wcO0uxKnaUA5Q3ieBuQO1IxZySKiMzWwcKiOM/FUDRiO1YxrI0sTvPZ/FbfsF8sbPR6Hv3hT/s/jRm3V/NxWD2216Bf342VLjaaqP72f9Bd62W/6v1uDuPvf5OEm5NSB/4NC9dAipouiv1jyyAEUbatB4/Hzl7Z6fPiiiuHsfmzU3ehTXz0GXpHpbKkeaeoX1Xwc7b390mr46vPFaLpsNrLxWBX3vV6/b/qm0drZ2RkN1M3NVE/6NzdutcbNzUSPpjc3jbDjKPzj/w "Python 3.8 (pre-release) – Try It Online"
the original, longer version is- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
```You can test with this code:```pythonfrom test_cases import casesfrom irish_possessive_golf import fdef test_all():for i, (x, y, result) in enumerate(cases):my_result = f(x, y)assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"print("All succeeded")test_all()- ```
- # [Python 3.8+], 577 bytes
- (was 634 than 591 bytes before)
- <!-- language-all: lang-python -->
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,R=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][R](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- [Try it online!][TIO-lv4qojcl]
- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
- [TIO-lv4qojcl]: https://tio.run/##jZu/bxu5Esd7/xWEimfpWRdc7poHH1xsvHFkwI4Ny3eNYRi0KFkC9AtaOYphpEiZ4ip36lKyuMqd2v3D8pbkzHCGayv3intLf74c8qOsZ6kFPH9YDmfT3/83X/z48ddBo1/aUfmPLr/Pyuf7cvO@/HZc/p2VX8/Kpz/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WfDWIUCI1CJLRJFuAYu@LTCXTEJ/lEBpBHgF3w6QQ74JN8EBMhQF3v6SR2vKfk8QsQOt1T8uSlohHB1s/PLi7xS/2ZOu/AkEuwSJ5GQIdFMnUuA7YeECVQj0X8IUOWAU0WCueMJKVNbTUZAe3q6yQ6@0vuiyznDESRZQLZ1xC6IXNibCJIIfVGHGvzauGwZvew/HqJDycYcJXIc8lBJ/IswXYbRq3InZgoAGox4eVkRJuti8AejthXSRgIxSP2LZJzVDyK39QkttswKR7x742iACoeia@MMqLN1kVgDyfl3yjYcdfCD2AuIMoBrMoyZBMUp5EVQO8UZ6IR0ODDsDavLYomp04OH844EjoxkScJdIqJLA3Y7QHSiwlvKIqgZMwETxnS5idLwV7O2TMbBkL3nD2zOUfZ8/i8lNhuwyR6zp/ZogBqnotntoxos3UR2APrld1OrVt2WbvkGAVj9@rWWiaHnXrX7PK22a33za5onN1653x5cfS6PC7Xx/n7M3SjsdDjqbyWQkueyuoh@/MQSfOUF0@KoTzPhQ8gDWrzL5aFvdEbx276xrFLbxy76RvHLr4C7CZvHCOovXHsxjeO3fSFY5e9cOym7xvri8HeL99nHzon2SE@By879APuIWJ5PQZOIpapyzRkXwolpdBVxJyxScuBuAh6/XpSmxdWTmPwkfz5LnwYu@6CfwgA8ghAG0B1IGXECkIA9YD4A2mcBUoAw4GUUW1E0YjwLL0@wcO0uxKnaUA5Q3ieBuQO1IxZySKiMzWwcKiOM/FUDRiO1YxrI0sTvPZ/FbfsF8sbPR6Hv3hT/s/jRm3V/NxWD2216Bf342VLjaaqP72f9Bd62W/6v1uDuPvf5OEm5NSB/4NC9dAipouiv1jyyAEUbatB4/Hzl7Z6fPiiiuHsfmzU3ehTXz0GXpHpbKkeaeoX1Xwc7b390mr46vPFaLpsNrLxWBX3vV6/b/qm0drZ2RkN1M3NVE/6NzdutcbNzUSPpjc3jbDjKPzj/w "Python 3.8 (pre-release) – Try It Online"
- A reference implementation, to understand the details.
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
#12: Post edited
**Python 3.8+, 577 bytes** (was 634 than 591 before)```pythonV="eéiíaáoóuúEÉIÍAÁOÓUÚ"r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}s=lambda a,b:a.upper()if b[0].isupper()else adef f(x,y):w,R=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][R](y)def e(w):for r in"bm cg dn fbh gn pb td".split():if w[0].lower()==r[0]:return r[1:]+wreturn[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]```# [Python 3.8 (pre-release)], 577 bytes- <!-- language-all: lang-python -->
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,R=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][R](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- [Try it online!][TIO-lv4qojcl]
- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
- [TIO-lv4qojcl]: https://tio.run/##jZu/bxu5Esd7/xWEimfpWRdc7poHH1xsvHFkwI4Ny3eNYRi0KFkC9AtaOYphpEiZ4ip36lKyuMqd2v3D8pbkzHCGayv3intLf74c8qOsZ6kFPH9YDmfT3/83X/z48ddBo1/aUfmPLr/Pyuf7cvO@/HZc/p2VX8/Kpz/LdWNncfDYmJS2sd9sTGaN9q@tdmNZbtzQwLAo/3FD3Wi/9SMLI8cm9yPjhuX3RaP9m8Oj26H7we3wnn6iDcz4rfVlpzgY68mt0Uq3b/f1m/v5vL9otkYDdXv16/WbUQE/6I@LvtI7pj9Qg@bn9kNrf9W@OFhcfb7@Y3VQNFdVeK@x26jmrdRo@uj37nb8RU@NeqjoaKr@Ur7Kaq@hGlWFPxb95f1iWo2vYAur/atV25cqmo1ho71q7a2u3u5fX1@9/a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39QkttswKR7x742iACoeia@MMqLN1kVgDyfl3yjYcdfCD2AuIMoBrMoyZBMUp5EVQO8UZ6IR0ODDsDavLYomp04OH844EjoxkScJdIqJLA3Y7QHSiwlvKIqgZMwETxnS5idLwV7O2TMbBkL3nD2zOUfZ8/i8lNhuwyR6zp/ZogBqnotntoxos3UR2APrld1OrVt2WbvkGAVj9@rWWiaHnXrX7PK22a33za5onN1653x5cfS6PC7Xx/n7M3SjsdDjqbyWQkueyuoh@/MQSfOUF0@KoTzPhQ8gDWrzL5aFvdEbx276xrFLbxy76RvHLr4C7CZvHCOovXHsxjeO3fSFY5e9cOym7xvri8HeL99nHzon2SE@By879APuIWJ5PQZOIpapyzRkXwolpdBVxJyxScuBuAh6/XpSmxdWTmPwkfz5LnwYu@6CfwgA8ghAG0B1IGXECkIA9YD4A2mcBUoAw4GUUW1E0YjwLL0@wcO0uxKnaUA5Q3ieBuQO1IxZySKiMzWwcKiOM/FUDRiO1YxrI0sTvPZ/FbfsF8sbPR6Hv3hT/s/jRm3V/NxWD2216Bf342VLjaaqP72f9Bd62W/6v1uDuPvf5OEm5NSB/4NC9dAipouiv1jyyAEUbatB4/Hzl7Z6fPiiiuHsfmzU3ehTXz0GXpHpbKkeaeoX1Xwc7b390mr46vPFaLpsNrLxWBX3vV6/b/qm0drZ2RkN1M3NVE/6NzdutcbNzUSPpjc3jbDjKPzj/w "Python 3.8 (pre-release) – Try It Online"
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- # [Python 3.8 (pre-release)], 577 bytes (was 634 than 591 before)
- <!-- language-all: lang-python -->
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,R=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][R](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]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/s/jRm3V/NxWD2216Bf342VLjaaqP72f9Bd62W/6v1uDuPvf5OEm5NSB/4NC9dAipouiv1jyyAEUbatB4/Hzl7Z6fPiiiuHsfmzU3ehTXz0GXpHpbKkeaeoX1Xwc7b390mr46vPFaLpsNrLxWBX3vV6/b/qm0drZ2RkN1M3NVE/6NzdutcbNzUSPpjc3jbDjKPzj/w "Python 3.8 (pre-release) – Try It Online"
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
#11: Post edited
**Python 3.8+, 584 bytes** (was 634 than 591 before)- ```python
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][rule](y)- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- ```
[Try it online!][TIO-lv4qag6b]- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
[TIO-lv4qag6b]: https://tio.run/##jZu/bxu5Esd7/xWEimfpWRdc7poHH1xsvHFkwI4Ny3eNYRi0KFkC9AtaOYphpEiZ4ip36lKyuMqd2v3D8pbkzHCGayv3intLf74c8qOsZ6kFPH9YDmfT3/83X/z48ddBo1/aUfmPLr/Pyuf7cvO@/HZc/p2VX8/Kpz/LdWNncfDYmJS2sd9sTGaN9q@tdmNZbtzQwLAo/3FD3Wi/9SMLI8cm9yPjhuX3RaP9m8Oj26H7we3wnn6iDcz4rfVlpzgY68mt0Uq3b/f1m/v5vL9otkYDdXv16/WbUQE/6I@LvtI7pj9Qg@bn9kNrf9Ve3I/7B4urz9d/rA6K5qrK7zV2G9XUlRpNH/323aa/6KlRDxUdTdVfyhda7TVUoyryx6K/vF9Mq/EV7GK1f7Vq@1JFszFstFetvdXV2/3r66u3v1RL7P92/WY8W/ktThtFTxUDVUxUMV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xllBFtti4Cezgp/0bBjrsWfgBzAVEOYFWWIZugOI2sAHqnOBONgAYfhrV5bVE0OXVy@HDGkdCJiTxJoFNMZGnAbg@QXkx4Q1EEJWMmeMqQNj9ZCvZyzp7ZMBC65@yZzTnKnsfnpcR2GybRc/7MFgVQ81w8s2VEm62LwB5Yr@x2at2yy9olxygYu1e31jI57NS7Zpe3zW69b3ZF4@zWO@fLi6PX5XG5Ps7fn6EbjYUeT@W1FFryVFYP2Z@HSJqnvHhSDOV5LnwAaVCbf7Es7I3eOHbTN45deuPYTd84dvEVYDd54xhB7Y1jN75x7KYvHLvshWM3fd9YXwz2fvk@@9A5yQ7xOXjZoR9wDxHL6zFwErFMXaYh@1IoKYWuIuaMTVoOxEXQ69eT2rywchqDj@TPd@HD2HUX/EMAkEcA2gCqAykjVhACqAfEH0jjLFACGA6kjGojikaEZ@n1CR6m3ZU4TQPKGcLzNCB3oGbMShYRnamBhUN1nImnasBwrGZcG1ma4LX/q7hlv1je6PE4/MWb8n8eN2qr5ue2emirRb@4Hy9bajRV/en9pL/Qy37T/90axN3/Jg83IacO/J8VqocWMV0U/cWSRw6gaFsNGo@fv7TV48MXVQxn92Oj7kaf@uox8IpMZ0v1SFO/qObjaO/tl1bDV58vRtNls5GNx6q47/X6fdM3jdbOzs5ooG5upnrSv7lxqzVubiZ6NL25aYQdR@Ef/wc "Python 3.8 (pre-release) – Try It Online"- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- **Python 3.8+, 577 bytes** (was 634 than 591 before)
- ```python
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,R=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][R](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- ```
- # [Python 3.8 (pre-release)], 577 bytes
- <!-- language-all: lang-python -->
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,R=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][R](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- [Try it online!][TIO-lv4qojcl]
- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
- [TIO-lv4qojcl]: https://tio.run/##jZu/bxu5Esd7/xWEimfpWRdc7poHH1xsvHFkwI4Ny3eNYRi0KFkC9AtaOYphpEiZ4ip36lKyuMqd2v3D8pbkzHCGayv3intLf74c8qOsZ6kFPH9YDmfT3/83X/z48ddBo1/aUfmPLr/Pyuf7cvO@/HZc/p2VX8/Kpz/LdWNncfDYmJS2sd9sTGaN9q@tdmNZbtzQwLAo/3FD3Wi/9SMLI8cm9yPjhuX3RaP9m8Oj26H7we3wnn6iDcz4rfVlpzgY68mt0Uq3b/f1m/v5vL9otkYDdXv16/WbUQE/6I@LvtI7pj9Qg@bn9kNrf9W@OFhcfb7@Y3VQNFdVeK@x26jmrdRo@uj37nb8RU@NeqjoaKr@Ur7Kaq@hGlWFPxb95f1iWo2vYAur/atV25cqmo1ho71q7a2u3u5fX1@9/aVaYv@36zfj2crvb9ooeqoYqGKiirkqlo03xXw8WjZbrf/4zbDgbc8M7ibzKtO6bsNKn/ar@nufVLXfT2Jzn9r966uL6@ZDy7v2m6vW/o4azBZqoVytierdKTNVg9uhupuq@a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O2TMbBkL3nD2zOUfZ8/i8lNhuwyR6zp/ZogBqnotntoxos3UR2APrld1OrVt2WbvkGAVj9@rWWiaHnXrX7PK22a33za5onN1653x5cfS6PC7Xx/n7M3SjsdDjqbyWQkueyuoh@/MQSfOUF0@KoTzPhQ8gDWrzL5aFvdEbx276xrFLbxy76RvHLr4C7CZvHCOovXHsxjeO3fSFY5e9cOym7xvri8HeL99nHzon2SE@By879APuIWJ5PQZOIpapyzRkXwolpdBVxJyxScuBuAh6/XpSmxdWTmPwkfz5LnwYu@6CfwgA8ghAG0B1IGXECkIA9YD4A2mcBUoAw4GUUW1E0YjwLL0@wcO0uxKnaUA5Q3ieBuQO1IxZySKiMzWwcKiOM/FUDRiO1YxrI0sTvPZ/FbfsF8sbPR6Hv3hT/s/jRm3V/NxWD2216Bf342VLjaaqP72f9Bd62W/6v1uDuPvf5OEm5NSB/4NC9dAipouiv1jyyAEUbatB4/Hzl7Z6fPiiiuHsfmzU3ehTXz0GXpHpbKkeaeoX1Xwc7b390mr46vPFaLpsNrLxWBX3vV6/b/qm0drZ2RkN1M3NVE/6NzdutcbNzUSPpjc3jbDjKPzj/w "Python 3.8 (pre-release) – Try It Online"
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
#10: Post edited
- **Python 3.8+, 584 bytes** (was 634 than 591 before)
- ```python
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][rule](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
```[Try it online!][TIO-lv4qag6b][Python 3.8 (pre-release)]: https://docs.python.org/3.8/[TIO-lv4qag6b]: https://tio.run/##jZu/bxu5Esd7/xWEimfpWRdc7poHH1xsvHFkwI4Ny3eNYRi0KFkC9AtaOYphpEiZ4ip36lKyuMqd2v3D8pbkzHCGayv3intLf74c8qOsZ6kFPH9YDmfT3/83X/z48ddBo1/aUfmPLr/Pyuf7cvO@/HZc/p2VX8/Kpz/LdWNncfDYmJS2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BCjQGgUIqFNsgDH2BWfTqAjPsknMoA8AuyCTyfYAZ/kg5gIAep6Tyex4z0lj1@A0OmekicvFY0Itn5@dnGJX@rP1HkHhlyCRfI0AjoskqlzGbD1gCiBeiziDxmyDGiyUDhnJCltaqvJCGhXXyfR2V9yX2Q5ZyCKLBPIvobQDZkTYxNBCqk34libVwuHNbuH5ddLfDjBgKtEnksOOpFnCbbbMGpF7sREAVCLCS8nI9psXQT2cMS@SsJAKB6xb5Gco@JR/KYmsd2GSfGIf28UBVDxSHxllBFtti4Cezgp/0bBjrsWfgBzAVEOYFWWIZugOI2sAHqnOBONgAYfhrV5bVE0OXVy@HDGkdCJiTxJoFNMZGnAbg@QXkx4Q1EEJWMmeMqQNj9ZCvZyzp7ZMBC65@yZzTnKnsfnpcR2GybRc/7MFgVQ81w8s2VEm62LwB5Yr@x2at2yy9olxygYu1e31jI57NS7Zpe3zW69b3ZF4@zWO@fLi6PX5XG5Ps7fn6EbjYUeT@W1FFryVFYP2Z@HSJqnvHhSDOV5LnwAaVCbf7Es7I3eOHbTN45deuPYTd84dvEVYDd54xhB7Y1jN75x7KYvHLvshWM3fd9YXwz2fvk@@9A5yQ7xOXjZoR9wDxHL6zFwErFMXaYh@1IoKYWuIuaMTVoOxEXQ69eT2rywchqDj@TPd@HD2HUX/EMAkEcA2gCqAykjVhACqAfEH0jjLFACGA6kjGojikaEZ@n1CR6m3ZU4TQPKGcLzNCB3oGbMShYRnamBhUN1nImnasBwrGZcG1ma4LX/q7hlv1je6PE4/MWb8n8eN2qr5ue2emirRb@4Hy9bajRV/en9pL/Qy37T/90axN3/Jg83IacO/J8VqocWMV0U/cWSRw6gaFsNGo@fv7TV48MXVQxn92Oj7kaf@uox8IpMZ0v1SFO/qObjaO/tl1bDV58vRtNls5GNx6q47/X6fdM3jdbOzs5ooG5upnrSv7lxqzVubiZ6NL25aYQdR@Ef/wc "Python 3.8 (pre-release) – Try It Online"
- **Python 3.8+, 584 bytes** (was 634 than 591 before)
- ```python
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][rule](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- ```
- [Try it online!][TIO-lv4qag6b]
- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
- [TIO-lv4qag6b]: https://tio.run/##jZu/bxu5Esd7/xWEimfpWRdc7poHH1xsvHFkwI4Ny3eNYRi0KFkC9AtaOYphpEiZ4ip36lKyuMqd2v3D8pbkzHCGayv3intLf74c8qOsZ6kFPH9YDmfT3/83X/z48ddBo1/aUfmPLr/Pyuf7cvO@/HZc/p2VX8/Kpz/LdWNncfDYmJS2sd9sTGaN9q@tdmNZbtzQwLAo/3FD3Wi/9SMLI8cm9yPjhuX3RaP9m8Oj26H7we3wnn6iDcz4rfVlpzgY68mt0Uq3b/f1m/v5vL9otkYDdXv16/WbUQE/6I@LvtI7pj9Qg@bn9kNrf9Ve3I/7B4urz9d/rA6K5qrK7zV2G9XUlRpNH/323aa/6KlRDxUdTdVfyhda7TVUoyryx6K/vF9Mq/EV7GK1f7Vq@1JFszFstFetvdXV2/3r66u3v1RL7P92/WY8W/ktThtFTxUDVUxUMVfFsvGmmI9Hy2ar9R@/GRa87ZnB3WReZVrXbVjp035Vf@@Tqvb7SWzuU7t/feXcrpsPLW/cb65a@ztqMFuohXLlJqp3p8xUDW6H6m6q5rdqaWj5KumK8i0cVB/T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C65@yZzTnKnsfnpcR2GybRc/7MFgVQ81w8s2VEm62LwB5Yr@x2at2yy9olxygYu1e31jI57NS7Zpe3zW69b3ZF4@zWO@fLi6PX5XG5Ps7fn6EbjYUeT@W1FFryVFYP2Z@HSJqnvHhSDOV5LnwAaVCbf7Es7I3eOHbTN45deuPYTd84dvEVYDd54xhB7Y1jN75x7KYvHLvshWM3fd9YXwz2fvk@@9A5yQ7xOXjZoR9wDxHL6zFwErFMXaYh@1IoKYWuIuaMTVoOxEXQ69eT2rywchqDj@TPd@HD2HUX/EMAkEcA2gCqAykjVhACqAfEH0jjLFACGA6kjGojikaEZ@n1CR6m3ZU4TQPKGcLzNCB3oGbMShYRnamBhUN1nImnasBwrGZcG1ma4LX/q7hlv1je6PE4/MWb8n8eN2qr5ue2emirRb@4Hy9bajRV/en9pL/Qy37T/90axN3/Jg83IacO/J8VqocWMV0U/cWSRw6gaFsNGo@fv7TV48MXVQxn92Oj7kaf@uox8IpMZ0v1SFO/qObjaO/tl1bDV58vRtNls5GNx6q47/X6fdM3jdbOzs5ooG5upnrSv7lxqzVubiZ6NL25aYQdR@Ef/wc "Python 3.8 (pre-release) – Try It Online"
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
#9: Post edited
- **Python 3.8+, 584 bytes** (was 634 than 591 before)
- ```python
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][rule](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
[Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
- **Python 3.8+, 584 bytes** (was 634 than 591 before)
- ```python
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][rule](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Try it online!][TIO-lv4qag6b]
- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
- [TIO-lv4qag6b]: https://tio.run/##jZu/bxu5Esd7/xWEimfpWRdc7poHH1xsvHFkwI4Ny3eNYRi0KFkC9AtaOYphpEiZ4ip36lKyuMqd2v3D8pbkzHCGayv3intLf74c8qOsZ6kFPH9YDmfT3/83X/z48ddBo1/aUfmPLr/Pyuf7cvO@/HZc/p2VX8/Kpz/LdWNncfDYmJS2sd9sTGaN9q@tdmNZbtzQwLAo/3FD3Wi/9SMLI8cm9yPjhuX3RaP9m8Oj26H7we3wnn6iDcz4rfVlpzgY68mt0Uq3b/f1m/v5vL9otkYDdXv16/WbUQE/6I@LvtI7pj9Qg@bn9kNrf9Ve3I/7B4urz9d/rA6K5qrK7zV2G9XUlRpNH/323aa/6KlRDxUdTdVfyhda7TVUoyryx6K/vF9Mq/EV7GK1f7Vq@1JFszFstFetvdXV2/3r66u3v1RL7P92/WY8W/ktThtFTxUDVUxUMVfFsvGmmI9Hy2ar9R@/GRa87ZnB3WReZVrXbVjp035Vf@@Tqvb7SWzuU7t/feXcrpsPLW/cb65a@ztqMFuohXLlJqp3p8xUDW6H6m6q5rdqaWj5KumK8i0cVB/Tr9f7YLtwQnurHRXGlXBj@ktjz/1f9d/rq2Zv/2AFW2r9t9nbW4l/itb1j54u@oU6UFc7TX@ztFVDL8rvU3cx2Q2XrXYF3a3DoeHQ3UgcajUU1CaUQX@fcVrdcGr6C5/ubjyecHdgGtEmWUJwMLstv/vYZKZuh@6amyE0AoIZQq1uGbIJitPQCqGTmrCpoITYGwmujazNIMosyuc7TTphJIQoYJIASlGg2rvAtob5dJKjQNDjJVCQIqAoMtqk64gAiPbK5yV69oZ@wDUJG4lBkrBWPQ5tCtlUFCTs/O74dNCjgLeTCW2S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ykjVhACqAfEH0jjLFACGA6kjGojikaEZ@n1CR6m3ZU4TQPKGcLzNCB3oGbMShYRnamBhUN1nImnasBwrGZcG1ma4LX/q7hlv1je6PE4/MWb8n8eN2qr5ue2emirRb@4Hy9bajRV/en9pL/Qy37T/90axN3/Jg83IacO/J8VqocWMV0U/cWSRw6gaFsNGo@fv7TV48MXVQxn92Oj7kaf@uox8IpMZ0v1SFO/qObjaO/tl1bDV58vRtNls5GNx6q47/X6fdM3jdbOzs5ooG5upnrSv7lxqzVubiZ6NL25aYQdR@Ef/wc "Python 3.8 (pre-release) – Try It Online"
#8: Post edited
- **Python 3.8+, 584 bytes** (was 634 than 591 before)
- ```python
V="eéiíaáoóuúEÉIÍAÁOÓUÚ";r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)};s=lambda a,b:a.upper()if b[0].isupper()else a- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][rule](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
- **Python 3.8+, 584 bytes** (was 634 than 591 before)
- ```python
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ"
- r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)}
- s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][rule](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
#7: Post edited
**Python 591 bytes** (was 634 before)- ```python
V="eéiíaáoóuúEÉIÍAÁOÓUÚ";r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)};s=lambda a,b:a.upper() if b[0].isupper() else a- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][rule](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
if w[0]in V:return"n"+w if w[0].isupper()else"n-"+wreturn w- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
- **Python 3.8+, 584 bytes** (was 634 than 591 before)
- ```python
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ";r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)};s=lambda a,b:a.upper()if b[0].isupper()else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][rule](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- return[w,"n-"+w,"n"+w][(c:=w[0]in V)*(c+w[0].isupper())]
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
#6: Post edited
**Python 634 bytes**- ```python
L,H,E=range(3);V="eéiíaáoóuúEÉIÍAÁOÓUÚ";r={"mé":("mo",L),"tú":("do",L),"sí":("a",H),"sé":("a",L),"muid":("ár",E),"sibh":("bhur",E),"siad":("a",E)};s=lambda a,b:a.upper() if b[0].isupper() else adef f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[l,lambda v:"h"+v if v[0] in V else v,e][rule](y)def l(w):if w[:2].lower()in"sc sf sm sp st".split():return wif w[0].lower()in"bcdfgmpst":return w[0]+s("h",w)+w[1:]return w- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
if w[0]in V:return"n"+w if w[0].isupper() else"n-"+w- return w
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
- **Python 591 bytes** (was 634 before)
- ```python
- V="eéiíaáoóuúEÉIÍAÁOÓUÚ";r={"mé":("mo",0),"tú":("do",0),"sí":("a",1),"sé":("a",0),"muid":("ár",2),"sibh":("bhur",2),"siad":("a",2)};s=lambda a,b:a.upper() if b[0].isupper() else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[lambda w:[w,w[0]+s("h",w)+w[1:]][1-(w[:2].lower()in"sc sf sm sp st".split())&(w[0].lower()in"bcdfgmpst")],lambda v:"h"+v if v[0]in V else v,e][rule](y)
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- if w[0]in V:return"n"+w if w[0].isupper()else"n-"+w
- return w
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
#5: Post edited
**Python 647 bytes**- ```python
L,H,E=range(3);V=set("eéiíaáoóuúEÉIÍAÁOÓUÚ");r={"mé":("mo",L),"tú":("do",L),"sí":("a",H),"sé":("a",L),"muid":("ár",E),"sibh":("bhur",E),"siad":("a",E)};s=lambda a,b:a.upper() if b[0].isupper() else adef f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ", y);return w+[l,lambda v:"h"+v if v[0] in V else v,e][rule](y)- def l(w):
- if w[:2].lower()in"sc sf sm sp st".split():return w
if w[0].lower()in set("bcdfgmpst"):return w[0]+s("h",w)+w[1:]- return w
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
if w[0] in V:return"n"+w if w[0].isupper() else"n-"+w- return w
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
- **Python 634 bytes**
- ```python
- L,H,E=range(3);V="eéiíaáoóuúEÉIÍAÁOÓUÚ";r={"mé":("mo",L),"tú":("do",L),"sí":("a",H),"sé":("a",L),"muid":("ár",E),"sibh":("bhur",E),"siad":("a",E)};s=lambda a,b:a.upper() if b[0].isupper() else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ",y);return w+[l,lambda v:"h"+v if v[0] in V else v,e][rule](y)
- def l(w):
- if w[:2].lower()in"sc sf sm sp st".split():return w
- if w[0].lower()in"bcdfgmpst":return w[0]+s("h",w)+w[1:]
- return w
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- if w[0]in V:return"n"+w if w[0].isupper() else"n-"+w
- return w
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
#4: Post edited
**Python 654 bytes**- ```python
- L,H,E=range(3);V=set("eéiíaáoóuúEÉIÍAÁOÓUÚ");r={"mé":("mo",L),"tú":("do",L),"sí":("a",H),"sé":("a",L),"muid":("ár",E),"sibh":("bhur",E),"siad":("a",E)};s=lambda a,b:a.upper() if b[0].isupper() else a
def f(x,y):w,rule=r[x];w=s(w[0]+"'" if w in{"mo","do"}and y[0]in V else w+" ", y);return w+[l,lambda v:"h"+v if v[0] in V else v,e][rule](y)- def l(w):
if w[:2].lower() in "sc sf sm sp st".split():return wif w[0].lower() in set("bcdfgmpst"):return w[0]+s("h",w)+w[1:]- return w
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
if w[0].lower() == r[0]:return r[1:]+wif w[0] in V:return"n"+w if w[0].isupper() else "n-"+w- return w
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
- **Python 647 bytes**
- ```python
- L,H,E=range(3);V=set("eéiíaáoóuúEÉIÍAÁOÓUÚ");r={"mé":("mo",L),"tú":("do",L),"sí":("a",H),"sé":("a",L),"muid":("ár",E),"sibh":("bhur",E),"siad":("a",E)};s=lambda a,b:a.upper() if b[0].isupper() else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'"if w in{"mo","do"}and y[0]in V else w+" ", y);return w+[l,lambda v:"h"+v if v[0] in V else v,e][rule](y)
- def l(w):
- if w[:2].lower()in"sc sf sm sp st".split():return w
- if w[0].lower()in set("bcdfgmpst"):return w[0]+s("h",w)+w[1:]
- return w
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower()==r[0]:return r[1:]+w
- if w[0] in V:return"n"+w if w[0].isupper() else"n-"+w
- return w
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
#3: Post edited
- **Python 654 bytes**
- ```python
- L,H,E=range(3);V=set("eéiíaáoóuúEÉIÍAÁOÓUÚ");r={"mé":("mo",L),"tú":("do",L),"sí":("a",H),"sé":("a",L),"muid":("ár",E),"sibh":("bhur",E),"siad":("a",E)};s=lambda a,b:a.upper() if b[0].isupper() else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'" if w in{"mo","do"}and y[0]in V else w+" ", y);return w+[l,lambda v:"h"+v if v[0] in V else v,e][rule](y)
- def l(w):
- if w[:2].lower() in "sc sf sm sp st".split():return w
- if w[0].lower() in set("bcdfgmpst"):return w[0]+s("h",w)+w[1:]
- return w
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower() == r[0]:return r[1:]+w
- if w[0] in V:return"n"+w if w[0].isupper() else "n-"+w
- return w
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
def same_case(a, b) -> str:if b[0].isupper():return a.upper()return a.lower()- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
rule_dict = {"mé": ("mo", "lenition"),"tú": ("do", "lenition"),"sí": ("a", "h-prothesis"),"sé": ("a", "lenition"),"muid": ("ár", "eclipsis"),"sibh": ("bhur", "eclipsis"),"siad": ("a", "eclipsis"),}- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
- **Python 654 bytes**
- ```python
- L,H,E=range(3);V=set("eéiíaáoóuúEÉIÍAÁOÓUÚ");r={"mé":("mo",L),"tú":("do",L),"sí":("a",H),"sé":("a",L),"muid":("ár",E),"sibh":("bhur",E),"siad":("a",E)};s=lambda a,b:a.upper() if b[0].isupper() else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'" if w in{"mo","do"}and y[0]in V else w+" ", y);return w+[l,lambda v:"h"+v if v[0] in V else v,e][rule](y)
- def l(w):
- if w[:2].lower() in "sc sf sm sp st".split():return w
- if w[0].lower() in set("bcdfgmpst"):return w[0]+s("h",w)+w[1:]
- return w
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower() == r[0]:return r[1:]+w
- if w[0] in V:return"n"+w if w[0].isupper() else "n-"+w
- return w
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
#2: Post edited
- **Python 654 bytes**
- ```python
- L,H,E=range(3);V=set("eéiíaáoóuúEÉIÍAÁOÓUÚ");r={"mé":("mo",L),"tú":("do",L),"sí":("a",H),"sé":("a",L),"muid":("ár",E),"sibh":("bhur",E),"siad":("a",E)};s=lambda a,b:a.upper() if b[0].isupper() else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'" if w in{"mo","do"}and y[0]in V else w+" ", y);return w+[l,lambda v:"h"+v if v[0] in V else v,e][rule](y)
- def l(w):
- if w[:2].lower() in "sc sf sm sp st".split():return w
- if w[0].lower() in set("bcdfgmpst"):return w[0]+s("h",w)+w[1:]
- return w
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower() == r[0]:return r[1:]+w
- if w[0] in V:return"n"+w if w[0].isupper() else "n-"+w
- return w
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
```
- **Python 654 bytes**
- ```python
- L,H,E=range(3);V=set("eéiíaáoóuúEÉIÍAÁOÓUÚ");r={"mé":("mo",L),"tú":("do",L),"sí":("a",H),"sé":("a",L),"muid":("ár",E),"sibh":("bhur",E),"siad":("a",E)};s=lambda a,b:a.upper() if b[0].isupper() else a
- def f(x,y):w,rule=r[x];w=s(w[0]+"'" if w in{"mo","do"}and y[0]in V else w+" ", y);return w+[l,lambda v:"h"+v if v[0] in V else v,e][rule](y)
- def l(w):
- if w[:2].lower() in "sc sf sm sp st".split():return w
- if w[0].lower() in set("bcdfgmpst"):return w[0]+s("h",w)+w[1:]
- return w
- def e(w):
- for r in"bm cg dn fbh gn pb td".split():
- if w[0].lower() == r[0]:return r[1:]+w
- if w[0] in V:return"n"+w if w[0].isupper() else "n-"+w
- return w
- ```
- the original, longer version is
- ```python
- vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ")
- def f(x, y):
- possessive_pronoun, rule = rule_dict[x]
- if possessive_pronoun in {"mo", "do"} and y[0] in vowels:
- possessive_pronoun = same_case(possessive_pronoun[0], y) + "'"
- else:
- possessive_pronoun = possessive_pronoun + " "
- if y[0].isupper():
- possessive_pronoun = possessive_pronoun.upper()
- if rule == "lenition":
- y = lenition(y)
- if rule == "h-prothesis":
- y = h_prothesis(y)
- if rule == "eclipsis":
- y = eclipsis(y)
- return possessive_pronoun + y
- def h_prothesis(word: str) -> str:
- if word[0] in vowels:
- return "h" + word
- return word
- def lenition(word: str) -> str:
- l1 = "sc sf sm sp st".split()
- if word[:2].lower() in l1:
- return word
- if word[0].lower() in set("bcdfgmpst"):
- return word[0] + same_case("h", word) + word[1:]
- return word
- def same_case(a, b) -> str:
- if b[0].isupper():
- return a.upper()
- return a.lower()
- def eclipsis(word: str) -> str:
- rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"]
- for r in rules:
- if word[0].lower() == r[0]:
- word = r[1:] + word
- return word
- if word[0] in vowels:
- if word[0] != word[0].lower():
- return "n" + word
- else:
- return "n-" + word
- return word
- rule_dict = {
- "mé": ("mo", "lenition"),
- "tú": ("do", "lenition"),
- "sí": ("a", "h-prothesis"),
- "sé": ("a", "lenition"),
- "muid": ("ár", "eclipsis"),
- "sibh": ("bhur", "eclipsis"),
- "siad": ("a", "eclipsis"),
- }
- ```
- You can test with this code:
- ```python
- from test_cases import cases
- from irish_possessive_golf import f
- def test_all():
- for i, (x, y, result) in enumerate(cases):
- my_result = f(x, y)
- assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
- print("All succeeded")
- test_all()
- ```
- [Test cases are here](https://gist.github.com/horvatha/1f898b03c79b86ff11a9a807999e4556)
#1: Initial revision
**Python 654 bytes** ```python L,H,E=range(3);V=set("eéiíaáoóuúEÉIÍAÁOÓUÚ");r={"mé":("mo",L),"tú":("do",L),"sí":("a",H),"sé":("a",L),"muid":("ár",E),"sibh":("bhur",E),"siad":("a",E)};s=lambda a,b:a.upper() if b[0].isupper() else a def f(x,y):w,rule=r[x];w=s(w[0]+"'" if w in{"mo","do"}and y[0]in V else w+" ", y);return w+[l,lambda v:"h"+v if v[0] in V else v,e][rule](y) def l(w): if w[:2].lower() in "sc sf sm sp st".split():return w if w[0].lower() in set("bcdfgmpst"):return w[0]+s("h",w)+w[1:] return w def e(w): for r in"bm cg dn fbh gn pb td".split(): if w[0].lower() == r[0]:return r[1:]+w if w[0] in V:return"n"+w if w[0].isupper() else "n-"+w return w ``` the original, longer version is ```python vowels = set("eéiíaáoóuúEÉIÍAÁOÓUÚ") def f(x, y): possessive_pronoun, rule = rule_dict[x] if possessive_pronoun in {"mo", "do"} and y[0] in vowels: possessive_pronoun = same_case(possessive_pronoun[0], y) + "'" else: possessive_pronoun = possessive_pronoun + " " if y[0].isupper(): possessive_pronoun = possessive_pronoun.upper() if rule == "lenition": y = lenition(y) if rule == "h-prothesis": y = h_prothesis(y) if rule == "eclipsis": y = eclipsis(y) return possessive_pronoun + y def h_prothesis(word: str) -> str: if word[0] in vowels: return "h" + word return word def lenition(word: str) -> str: l1 = "sc sf sm sp st".split() if word[:2].lower() in l1: return word if word[0].lower() in set("bcdfgmpst"): return word[0] + same_case("h", word) + word[1:] return word def same_case(a, b) -> str: if b[0].isupper(): return a.upper() return a.lower() def eclipsis(word: str) -> str: rules = ["bm", "cg", "dn", "fbh", "gn", "pb", "td"] for r in rules: if word[0].lower() == r[0]: word = r[1:] + word return word if word[0] in vowels: if word[0] != word[0].lower(): return "n" + word else: return "n-" + word return word rule_dict = { "mé": ("mo", "lenition"), "tú": ("do", "lenition"), "sí": ("a", "h-prothesis"), "sé": ("a", "lenition"), "muid": ("ár", "eclipsis"), "sibh": ("bhur", "eclipsis"), "siad": ("a", "eclipsis"), } ``` You can test with this code: ```python from test_cases import cases from irish_possessive_golf import f def test_all(): for i, (x, y, result) in enumerate(cases): my_result = f(x, y) assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})" print("All succeeded") test_all() ```