-- Writeup at https://work.njae.me.uk/2023/12/01/advent-of-code-2023-day-01/
import AoC
--- import Data.Char
import Data.List
import qualified Data.MultiSet as MS
do dataFileName <- getDataFileName
text <- readFile dataFileName
let pairs = fmap readPair $ lines text
- print pairs
print $ part1 pairs
print $ part2 pairs
-part1 :: [(Int, Int)] -> Int
+part1, part2 :: [(Int, Int)] -> Int
part1 pairs = sum $ zipWith absDiff (sort lefts) (sort rights)
where (lefts, rights) = unzip pairs
absDiff a b = abs (a - b)
common warnings
ghc-options: -Wall
+common common-modules
+ other-modules: AoC
+
common common-extensions
default-extensions: AllowAmbiguousTypes
, ApplicativeDo
default-language: GHC2021
executable advent01
- import: warnings, common-extensions, build-directives
+ import: warnings, common-extensions, build-directives, common-modules
main-is: advent01/Main.hs
build-depends: multiset