Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr committed Dec 1, 2024
1 parent b9d7165 commit e148a4d
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Aoc2024/Day01.lean
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Aoc2024.Day01

def splitOnWhitespace (s : String) : List String :=
s.split .isWhitespace) |>.filter (· ≠ "")
s.split Char.isWhitespace |> .filter (· ≠ "")

def parseNumber (s: String) : Except String Int :=
match s.toInt? with
Expand Down Expand Up @@ -33,10 +33,7 @@ def parseAndSolvePart1 (s : String) : Except String Int :=

def solvePart2 (pairs : List (Int × Int)) : Int :=
let (firsts, seconds) := pairs.unzip
let countOccurrencesInSeconds (n : Int) : Int :=
seconds.filter (· == n) |>.length
let similarityScore (n : Int) : Int :=
countOccurrencesInSeconds n * n
let similarityScore (n : Int) : Int := seconds.filter (· == n) |>.length |> (· * n)
firsts.map similarityScore |> sumList

def parseAndSolvePart2 (s : String) : Except String Int :=
Expand Down

0 comments on commit e148a4d

Please sign in to comment.