diff options
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)) |