Compare commits

..

4 Commits

  1. 28
      2023/8.py
  2. 12
      2023/9.py
  3. 4
      README.md

@ -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)

@ -2,8 +2,8 @@ my solutions for the [Advent of Code](https://adventofcode.com/)
in progress:\
2021: 12/25\
2022: 7/25\
2023: 3/25
2022: 8/25\
2023: 9/25
planned:\
2020\

Loading…
Cancel
Save