My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 22 lines 442 B view raw
1import fileinput 2from itertools import count 3 4banks = [int(n) for n in fileinput.input()[0].split()] 5seen = {} 6 7for i in count(start=1): 8 m = max(banks) 9 idx = banks.index(m) 10 banks[idx] = 0 11 12 for j in range(1, m + 1): 13 banks[(idx + j) % len(banks)] += 1 14 15 t = tuple(banks) 16 if t in seen: 17 break 18 19 seen[t] = i 20 21print "Number of redistribution cycles:", i 22print "Length of infinite loop cycle:", i - seen[t]