Skip to content

Instantly share code, notes, and snippets.

@AntonFagerberg
Created November 2, 2016 20:58
Show Gist options
  • Save AntonFagerberg/52e01c359779413a07e63f1803780185 to your computer and use it in GitHub Desktop.
Save AntonFagerberg/52e01c359779413a07e63f1803780185 to your computer and use it in GitHub Desktop.
Advent of code 2015 - 1 - Haskell
num :: Char -> Int
num '(' = 1
num ')' = -1
main = readFile "input" >>= putStrLn . show . sum . map num
f :: (Int, Int) -> Int -> (Int, Int)
f (a, b) c = (a + c, b + 1)
cellar :: (Int, Int) -> Bool
cellar = (/=) (-1) . fst
main2 = readFile "input" >>= putStrLn . show . snd . head . dropWhile cellar . scanl f (0, 0) . map num
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment