Roderic Day 2 år sedan
förälder
incheckning
ce251f3513
1 ändrade filer med 20 tillägg och 0 borttagningar
  1. +20
    -0
      y2022/p09.py

+ 20
- 0
y2022/p09.py Visa fil

@@ -0,0 +1,20 @@
def move(diff):
dt = 0
if max(abs(diff.real), abs(diff.imag)) > 1:
dt += diff.real and diff.real / abs(diff.real)
dt += diff.imag and (diff.imag / abs(diff.imag)) * 1j
return dt


moves = dict(zip('LRUD', [-1, 1, -1j, 1j]))
state = {i: 0 for i in range(10)}
history = {i: set() for i in state}
for instruction in open(0).read().splitlines():
k, v = instruction.split()
for step in k * int(v):
for i in state:
state[i] += move(state[i - 1] - state[i]) if i else moves[k]
history[i].add(state[i])

print(len(history[0]))
print(len(history[9]))

Laddar…
Avbryt
Spara