blob: 184f56bdb8f1d28ae94674ce1fb88ee37f7bff99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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))
|