Advent of Code 2025 in Lean 4 – Day 6
hamberg.no·1d
🧠Lisp Dialects
Preview
Report Post

Today’s problem was all about reading numbers from the input file, so I first added the words function from Haskell to my utility library:

def String.words (s : String) : List String :=
s.splitOn " " |> List.filter (!·.isEmpty)

In the problem, we also read in the operations to be performed on the numbers. I initially parsed '+' and '*' into a pair of the function and the neutral element for the operation, but then found out that List.sum will use the Add and Zero instance for the type instance and do the right thing. However, there was no List.prod in Lean’s standard library1, so I d…

Similar Posts

Loading similar posts...