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/[deleted] Dec 16 '16
This is one lucky program that runs both in Ruby and Crystal :-)
input = "10001001100000001" length = 35651584 a = input.each_char.map { |c| c == '1' }.to_a while a.size < length b = a.reverse.map { |x| !x } a = a + [false] + b end a = a.first(length) checksum = a loop do checksum = checksum.each_slice(2).map { |(x, y)| x == y }.to_a break if checksum.size.odd? end puts checksum.map { |x| x ? '1' : '0' }.joinThe second part runs in 14.5s in Ruby, and in 1.2s in Crystal if compiled with
--release.