advent of code solutions op.tngl.io
haskell aoc
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

2017: add all

Signed-off-by: oppiliappan <me@oppi.li>

+54
+12
src/2017/01.lhs
··· 1 + import qualified Data.Char as C 2 + import System.Environment (getArgs) 3 + 4 + main = do 5 + args <- getArgs 6 + n <- case args of 7 + ["-"] -> getContents 8 + [file] -> readFile file 9 + let f = map C.digitToInt $ init n 10 + l = length f 11 + print $ sum $ map fst $ filter (uncurry (==)) $ zip f (tail f ++ [head f]) 12 + print $ sum $ map fst $ filter (uncurry (==)) $ zip f (drop (l `div` 2) (cycle f))
+23
src/2017/02.lhs
··· 1 + import Control.Arrow ((&&&)) 2 + import Data.List (maximum, minimum) 3 + import Data.List.Split (splitOn) 4 + import System.Environment (getArgs) 5 + 6 + parse = map read . splitOn "\t" 7 + 8 + checksum = uncurry (-) . (maximum &&& minimum) 9 + 10 + divisible ls = sum [x `div` y | x <- ls, y <- ls, x `rem` y == 0, x /= y] 11 + 12 + p1 = sum . map checksum 13 + 14 + p2 = sum . map divisible 15 + 16 + main = do 17 + args <- getArgs 18 + n <- case args of 19 + ["-"] -> getContents 20 + [file] -> readFile file 21 + let f = map parse $ lines n 22 + print $ p1 f 23 + print $ p2 f
+19
src/2017/03.lhs
··· 1 + import Data.List (maximum, minimum) 2 + import Data.List.Split (splitOn) 3 + import System.Environment (getArgs) 4 + 5 + ring = toInteger . ceiling . (/ 2) . subtract 1 . sqrt . fromInteger 6 + 7 + p1 n = curr + mid 8 + where 9 + curr = ring n 10 + prev = (2 * curr - 1) ^ 2 11 + mid = minimum $ map (abs . subtract n . (+ prev) . (* curr)) [1, 3, 5, 7] 12 + 13 + main = do 14 + args <- getArgs 15 + n <- case args of 16 + ["-"] -> getContents 17 + [file] -> readFile file 18 + let f = read $ init n 19 + print $ p1 f