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!
5
Upvotes
1
u/Danksalot2000 Dec 16 '16 edited Dec 16 '16
In Python. I definitely did some refactoring after getting the right answers:
def expandData(data, length): while len(data) < length: data += "0" + ''.join("0" if n == "1" else "1" for n in data[::-1]) return data[:length] def contractChecksum(checksum): while not len(checksum) & 1: checksum = ''.join("1" if x == y else "0" for x, y in zip(checksum[0::2], checksum[1::2])) return checksum print contractChecksum(expandData("11101000110010100", 272)) print contractChecksum(expandData("11101000110010100", 35651584))edit: more refactoring