advent-of-code/aoc.hs
2024-12-03 00:24:29 +11:00

28 lines
738 B
Haskell

module Aoc where
aocMain :: Show p => ([String] -> p) -> (p -> Int) -> (p -> Int) -> IO ()
aocMain parseFile part1 part2 = do
contents <- readFile "input.txt"
let input = parseFile $ lines contents
-- putStrLn $ "Input: " ++ show input
putStrLn $ "Part 1: " ++ show (part1 input)
putStrLn $ "Part 2: " ++ show (part2 input)
enumerate :: [a] -> [(Int, a)]
enumerate xs = zip [0..length xs] xs
unimplemented :: Show p => p -> Int
unimplemented = error . show
pair :: [a] -> (a, a)
pair as = let [a1, a2] = as in (a1, a2)
triplet :: [a] -> (a, a, a)
triplet as = let [a1, a2, a3] = as in (a1, a2, a3)
single :: [a] -> a
single as = let [a] = as in a
both :: (a -> b) -> (a, a) -> (b, b)
both f (a, b) = (f a, f b)