summaryrefslogtreecommitdiff
path: root/Day3.lean
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2024-11-22 22:10:48 +0100
committerAndreas Grois <andi@grois.info>2024-11-22 22:10:48 +0100
commitce7214e07a766bc1e5ab02346e42eb6ca441c509 (patch)
tree5bf9378891e3ed6478757770b71d6008a452bf63 /Day3.lean
parente9f48c21f878f727778e17294217c2094a595e5d (diff)
Fix deprecation warnings for Lean 4.13
Diffstat (limited to 'Day3.lean')
-rw-r--r--Day3.lean8
1 files changed, 4 insertions, 4 deletions
diff --git a/Day3.lean b/Day3.lean
index fbc9e3e..8bf0874 100644
--- a/Day3.lean
+++ b/Day3.lean
@@ -91,7 +91,7 @@ def parse (schematic : String) : Except String Schematic := do
def part1 (schematic : Schematic) : Nat :=
-- fast lookup: We need to know if a part is at a given coordinate
- open Lean(HashSet) in
+ open Std(HashSet) in
let partCoordinates := HashSet.insertMany HashSet.empty $ schematic.parts.map Part.position
let partNumbers := schematic.numbers.filter λnumber ↦
number.positions.any λposition ↦
@@ -101,13 +101,13 @@ def part1 (schematic : Schematic) : Nat :=
def part2 (schematic : Schematic) : Nat :=
-- and now it is obvious that keeping the parsed input free of opinions was a good idea.
-- because here we need quick lookup for the numbers, not the parts.
- open Lean(HashMap) in
+ open Std(HashMap) in
let numberCoordinates : HashMap Coordinate PartNumber :=
- Lean.HashMap.ofList $ schematic.numbers.bind $ λ pn ↦ pn.positions.map (·, pn)
+ HashMap.ofList $ schematic.numbers.bind $ λ pn ↦ pn.positions.map (·, pn)
let gearSymbols := schematic.parts.filter (Part.symbol · == '*')
-- but the symbols aren't enough, they need to be adjacent to **exactly** 2 numbers
let numbersNextGearSymbols := List.eraseReps <$> gearSymbols.map λgs ↦
- gs.position.adjacents.filterMap numberCoordinates.find?
+ gs.position.adjacents.filterMap numberCoordinates.get?
let gearSymbols := numbersNextGearSymbols.filter (List.length · == 2)
let gearRatios := gearSymbols.map $ List.foldl (· * PartNumber.value ·) 1
gearRatios.foldl (· + ·) 0