Compare commits
4 Commits
7c621efe50
...
68525204f4
Author | SHA1 | Date |
---|---|---|
kwout | 68525204f4 | 11 months ago |
kwout | 4021a73746 | 11 months ago |
kwout | 631b6db2a5 | 11 months ago |
kwout | db88b13008 | 11 months ago |
3 changed files with 42 additions and 2 deletions
@ -0,0 +1,28 @@ |
||||
from math import lcm |
||||
|
||||
input = open("input.txt", 'r').read().splitlines() |
||||
instructions = input[0] |
||||
nodes = {l.split()[0]: (l.split()[2][1:-1], l.split()[3][:-1]) for l in input[2:]} |
||||
|
||||
steps = 0 |
||||
node = 'AAA' |
||||
|
||||
while node != 'ZZZ': |
||||
node = nodes[node][0] if instructions[steps % len(instructions)] == 'L' else nodes[node][1] |
||||
steps += 1 |
||||
|
||||
|
||||
nodeGhost = [n for n in nodes if n[-1] == 'A'] |
||||
multiples = [] |
||||
|
||||
for n in nodeGhost: |
||||
stepsGhost = 0 |
||||
nodeTemp = n |
||||
while nodeTemp[-1] != 'Z': |
||||
nodeTemp = nodes[nodeTemp][0] if instructions[stepsGhost % len(instructions)] == 'L' else nodes[nodeTemp][1] |
||||
stepsGhost += 1 |
||||
multiples.append(stepsGhost) |
||||
|
||||
|
||||
print(steps) |
||||
print(lcm(*multiples)) |
@ -0,0 +1,12 @@ |
||||
input = [[int(i) for i in l.split()] for l in open("input.txt", 'r').read().splitlines()] |
||||
|
||||
def diff(l): |
||||
newList = [l[i+1] - l[i] for i in range(len(l)-1)] |
||||
return l[-1] + diff(newList) if set(newList) != {0} else l[-1] |
||||
|
||||
|
||||
score = sum(diff(l) for l in input) |
||||
score2 = sum(diff(l[::-1]) for l in input) |
||||
|
||||
print(score) |
||||
print(score2) |
Loading…
Reference in new issue