Something went wrong. Try again.
My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code
advent-of-code python
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435import fileinput
def generate_data(data, size): def dragon(a): b = ''.join('1' if c == '0' else '0' for c in a) return a + '0' + b[::-1]
while len(data) < size: data = dragon(data)
return data[:size]
def checksum(s): def checksum_iteration(s): tmp = [] for a, b in zip(s[::2], s[1::2]): tmp.append('1' if a == b else '0')
return ''.join(tmp)
res = checksum_iteration(s)
while len(res) % 2 == 0: res = checksum_iteration(res)
return res
if __name__ == '__main__': data = fileinput.input()[0].strip() print 'Checksum #1:', checksum(generate_data(data, 272)) print 'Checksum #2:', checksum(generate_data(data, 35651584))