Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day8(s, *, part2=False):
- lines = s.splitlines()
- routes = {line[:3]: (line[7:10], line[12:15]) for line in lines[2:]}
- def length(node, end):
- for index, ch in enumerate(itertools.cycle(lines[0])):
- if node.endswith(end):
- return index
- node = routes[node][ch == 'R']
- if part2:
- return math.lcm(*(length(node, 'Z') for node in routes if node.endswith('A')))
- return length('AAA', 'ZZZ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement