advent-of-code/aoc.hs

21 lines
613 B
Haskell
Raw Normal View History

2024-12-02 18:55:47 +11:00
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
-- print $ "Input: " ++ show input
print $ "Part 1: " ++ show (part1 input)
print $ "Part 2: " ++ show (part2 input)
enumerate :: [a] -> [(Int, a)]
2024-12-02 21:14:08 +11:00
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)