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 solution for 2016/16

+35
+34
2016/day16.py
··· 1 + import fileinput 2 + 3 + 4 + def generate_data(data, size): 5 + def dragon(a): 6 + b = ''.join('1' if c == '0' else '0' for c in a) 7 + return a + '0' + b[::-1] 8 + 9 + while len(data) < size: 10 + data = dragon(data) 11 + 12 + return data[:size] 13 + 14 + 15 + def checksum(s): 16 + def checksum_iteration(s): 17 + tmp = [] 18 + for a, b in zip(s[::2], s[1::2]): 19 + tmp.append('1' if a == b else '0') 20 + 21 + return ''.join(tmp) 22 + 23 + res = checksum_iteration(s) 24 + 25 + while len(res) % 2 == 0: 26 + res = checksum_iteration(res) 27 + 28 + return res 29 + 30 + 31 + if __name__ == '__main__': 32 + data = fileinput.input()[0].strip() 33 + print 'Checksum #1:', checksum(generate_data(data, 272)) 34 + print 'Checksum #2:', checksum(generate_data(data, 35651584))
+1
2016/input16.txt
··· 1 + 00101000101111010