diff options
author | Nat Lasseter <user@4574.co.uk> | 2024-12-02 13:50:18 +0000 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2024-12-02 13:50:18 +0000 |
commit | b975342263995c954354183d69a9d898bd38dc89 (patch) | |
tree | 2938ceb0cb9c47498550b0cc3a870d13eb0c8b67 /day01/day01.hs |
[Day 01] Done
Diffstat (limited to 'day01/day01.hs')
-rw-r--r-- | day01/day01.hs | 21 |
1 files changed, 21 insertions, 0 deletions
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)) |