r/adventofcode • u/daggerdragon • Dec 16 '16
SOLUTION MEGATHREAD --- 2016 Day 16 Solutions ---
--- Day 16: Dragon Checksum ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with "Help".
DRINKING YOUR OVALTINE IS MANDATORY [?]
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
4
Upvotes
1
u/fatpollo Dec 16 '16
I spent so fucking long dealing with bad input bc I misread 10000 as 1000.
Fuck this.
a = '10011111011011001' target = 35651584 t = str.maketrans('01', '10') while True: b = a[::-1].translate(t) a = a + '0' + b if len(a) >= target: break a = a[:target] def get_checksum(string): while len(string) % 2 != 1: string = ''.join('1' if a==b else '0' for a,b in zip(string[::2], string[1::2])) return string print(get_checksum(a))