Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day1(s, *, part2=False):
- values = {str(i): i for i in range(10)}
- if part2:
- strings = 'zero one two three four five six seven eight nine'.split()
- values |= {name: index for index, name in enumerate(strings)}
- pattern = f"({'|'.join(values)})"
- total = 0
- for line in s.splitlines():
- str0 = re.search(pattern, line).group(1)
- str1 = re.search(f'.*{pattern}', line).group(1)
- total += values[str0] * 10 + values[str1]
- return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement