Day01 #2
Closed this issue · 3 comments
cant0r commented
jabbalaci commented
? I don't get it.
cant0r commented
I was on mobile when I first opened this issue but I noticed some errors in my question regarding your Part 2 solution so I tried to revert this issue. Unfortunately, I couldn't on mobile, or at least, I did not find a way.
I was to inquiry about dynamically producing the regex pattern, I had an idea on how to do it but I couldn't decide whether the code would remain "pythonic" or not:
def process(line: str) -> int:
m = re.search(rf"[0-9]|{'|'.join([d for d in DIGITS)}", line)
assert m
first = text2number(m.group())
#
m = re.search(rf"[0-9]|{'|'.join([d[::-1] for d in DIGITS])}", line[::-1])
assert m
last = text2number(m.group()[::-1])
return first * 10 + last
jabbalaci commented
Here, I prefer the more explicit way that I find more readable. Thanks, anyway.