Compare commits
No commits in common. '68525204f47a8d71db13953295fd480ab6c9435b' and '7c621efe5076aad5046bb6040142a8df6ca82ded' have entirely different histories.
68525204f4
...
7c621efe50
3 changed files with 2 additions and 42 deletions
@ -1,28 +0,0 @@ |
||||
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)) |
@ -1,12 +0,0 @@ |
||||
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