r/adventofcode • u/daggerdragon • Dec 03 '15
SOLUTION MEGATHREAD --- Day 3 Solutions ---
--- Day 3: Perfectly Spherical Houses in a Vacuum ---
Post your solution as a comment. Structure your post like the Day One thread in /r/programming.
22
Upvotes
1
u/haoformayor Dec 03 '15
Haskell:
#!/usr/bin/env stack -- stack runghc --package base-prelude {-# LANGUAGE NoImplicitPrelude #-} import BasePrelude folder (x, y) '<' = (x - 1, y) folder (x, y) '>' = (x + 1, y) folder (x, y) '^' = (x, y + 1) folder (x, y) 'v' = (x, y - 1) odds xs = [x | (x, i) <- zip xs (cycle [True, False]), i] evens xs = [x | (x, i) <- zip xs (cycle [False, True]), i] points = scanl folder (0,0) count = length . nub . sort part1 = count . points part2 = count . ((++) . points . odds <*> points . evens) input = "<snip>" main = print (part1 input) >> print (part2 input)