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.

Add 2017/06

+25
+22
2017/day06.py
··· 1 + import fileinput 2 + from itertools import count 3 + 4 + banks = [int(n) for n in fileinput.input()[0].split()] 5 + seen = {} 6 + 7 + for 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 + 21 + print "Number of redistribution cycles:", i 22 + print "Length of infinite loop cycle:", i - seen[t]
+1
2017/inputs/06.txt
··· 1 + 0 5 10 0 11 14 13 4 11 8 8 7 1 4 12 11
+2
2017/outputs/06.txt
··· 1 + 7864 2 + 1695