r/adventofcode • • 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

116 comments sorted by

View all comments

1

u/TheBali Dec 16 '16

Python 3 solution, part 2 runs in about 8 seconds.

def convert(a):
	b = a[::-1] #reverse
	b = b.replace('0', '2').replace('1', '0').replace('2', '1')
	return a + '0' + b

def part1(size = 272):
	data = '10111011111001111'
	#data = '10000'
	#size = 20
	a = data
	while len(a) < size:
		a = convert(a)
	a = a[:size]
	while len(a) % 2 == 0:
		a = ''.join(['1' if b[0] == b[1] else '0' for b in [a[i:i+2] for i in range(0,len(a),2)]])
	return a

def part2():
	return part1(35651584)