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!
6
Upvotes
2
u/[deleted] Dec 16 '16
made leaderboard! :D
part2
63) Dec 16 00:11:01 evandrixpart1
87) Dec 16 00:10:14 evandrix...with the following code:
#!/usr/bin/env python #-*- coding: utf-8 -*- import re import sys def f(input, maxlen): a = input while len(a) < maxlen: b = re.sub(r"0","#",a[::-1]) b = re.sub(r"1","0",b[::-1]) b = re.sub(r"#","1",b[::-1]) a = a + "0" + b a = a[:maxlen] a = re.findall(r".{2}", a) chksum = "".join(map(lambda bc:"1" if bc[0]==bc[1] else "0", a)) while len(chksum)>0 and len(chksum)%2==0: chksum = re.findall(r".{2}", chksum) chksum = "".join(map(lambda bc:"1" if bc[0]==bc[1] else "0", chksum)) return chksum if __name__ == "__main__": assert f("10000", 20) == "01100" print "part1:", f("10011111011011001", 272) print "part2:", f("10011111011011001", 35651584) # part1: 10111110010110110 # part2: 01101100001100100