-
Notifications
You must be signed in to change notification settings - Fork 0
/
one.py
31 lines (26 loc) · 1.09 KB
/
one.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Number:
def __init__(self, value):
self.value = value
def __str__(self):
return self.__repr__()
def __repr__(self):
return f"{self.value}"
def mix(arrangement, n):
i = arrangement.index(n)
arrangement.remove(n)
arrangement.insert((i+n.value)%(len(arrangement)), n)
def grove_coords(filename):
with open(filename) as fileh:
original = [Number(int(line.strip())) for line in fileh]
zeroindex = [i for i, n in enumerate(original) if n.value == 0][0]
#print(f"{zeroindex=} {original[zeroindex]=}")
arrangement = original[:]
#print(original, arrangement)
for i in range(len(original)):
mix(arrangement, original[i])
#print(f"{i=}={original[i].value}\t {', '.join(str(a) for a in arrangement)}")
for grove in (1000, 2000, 3000):
print(f"{grove=} {arrangement[(grove+zeroindex)%len(original)]=}")
yield arrangement[(grove+arrangement.index(original[zeroindex]))%len(original)].value
print(sum(grove_coords("example")))
print(sum(grove_coords("input")))