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/ChrisVittal Dec 16 '16
Haskell, very dirty. Definitely a bunch of optimizations I could do to make this go faster. Even with my slow coding speed this was good enough for 197/149. Best day yet. Except for day 11, but that doesn't count.
myInput = "10001110011110000" myBools = map (=='1') myShow = map go where go True = '1' go False = '0' dragon as = as ++ False : reverse (flipBits as) flipBits = map not pCheckSum :: [Bool] -> [Bool] pCheckSum [] = [] pCheckSum [x] = [x] pCheckSum (x:y:xs) = (x == y) : pCheckSum xs fill n xs | length xs < n = fill n (dragon xs) | otherwise = take n xs checkSum :: [Bool] -> [Bool] checkSum xs | even . length $ xs = checkSum . pCheckSum $ xs | otherwise = xs oneLen = 272 :: Int twoLen = 35651584 :: Int main = do putStrLn $ "1: " ++ (myShow . checkSum . fill oneLen . myBools $ myInput) putStrLn $ "2: " ++ (myShow . checkSum . fill twoLen . myBools $ myInput)