diff options
author | JJ | 2025-01-02 02:23:31 +0000 |
---|---|---|
committer | JJ | 2025-01-02 02:23:31 +0000 |
commit | 356bc5b49033d0db5fb413ebd6d4bef4f86a511c (patch) | |
tree | 36a2c6fe66498a7dc409dbda621a355dd8f12cff | |
parent | 830b65d349ec148df049522a1875a8e3d5ce7697 (diff) |
-rw-r--r-- | 2024/lean/Solutions/Day01.lean | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/2024/lean/Solutions/Day01.lean b/2024/lean/Solutions/Day01.lean index 1a109df..b6f9dbe 100644 --- a/2024/lean/Solutions/Day01.lean +++ b/2024/lean/Solutions/Day01.lean @@ -1,15 +1,16 @@ -- Day 1: Historian Hysteria def solution (input : String) : String := - let input := input.stripSuffix "\n"|>.splitOn "\n" - let l1 := input.map <| fun x => x.splitOn " " |>.get! 0 |>.toInt! - let l2 := input.map <| fun x => x.splitOn " " |>.get! 1 |>.toInt! + 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.zipWith (fun a b => (a - b).natAbs) l1.mergeSort l2.mergeSort + 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 + List.foldl (· + ·) 0 + <| List.map (fun a => a * List.count a l2) l1 s!"{p1}, {p2}" -- def main (args : List String) : IO Unit := do |