aboutsummaryrefslogtreecommitdiff
path: root/2024/lean/Solutions/Day01.lean
blob: b6f9dbe95e4c3a5622b1ed9ba1a16bebd7ff597c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-- Day 1: Historian Hysteria

def solution (input : String) : String :=
  let input := input.stripSuffix "\n" |>.splitOn "\n"
  let l1 := input.map (·.splitOn "   " |>.get! 0 |>.toInt!)
  let l2 := input.map (·.splitOn "   " |>.get! 1 |>.toInt!)
  let p1 :=
    List.foldl (· + ·) 0
    <| List.map Int.natAbs
    <| List.zipWith (· - ·) l1.mergeSort l2.mergeSort
  let p2 :=
    List.foldl (· + ·) 0
    <| List.map (fun a => a * List.count a l2) l1
  s!"{p1}, {p2}"

-- def main (args : List String) : IO Unit := do
--   let input <- IO.FS.readFile s!"../input/{args.get! 0|>.toLower}.txt"
--   IO.println <| solution input