From b975342263995c954354183d69a9d898bd38dc89 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 2 Dec 2024 13:50:18 +0000 Subject: [Day 01] Done --- day01/day01.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 day01/day01.hs (limited to 'day01/day01.hs') diff --git a/day01/day01.hs b/day01/day01.hs new file mode 100644 index 0000000..184f56b --- /dev/null +++ b/day01/day01.hs @@ -0,0 +1,21 @@ +import Data.List +import Data.List.Split + +part1 fst sec = + let + sfst = sort fst + ssec = sort sec + z = map (abs) $ zipWith (-) sfst ssec in + sum z + +part2 fst sec = + sum $ map (\x -> x * (length $ filter (== x) sec)) fst + +main = do + file <- readFile "day01.input" + let lns = lines file + let lsts = transpose $ map (splitOn " ") lns + let fst = map (read::String->Int) $ head lsts + let sec = map (read::String->Int) $ head $ reverse lsts + putStrLn ("Part 1: " ++ (show $ part1 fst sec)) + putStrLn ("Part 2: " ++ (show $ part2 fst sec)) -- cgit v1.2.1