diff options
| author | Andreas Grois <andi@grois.info> | 2024-12-01 19:57:39 +0100 |
|---|---|---|
| committer | Andreas Grois <andi@grois.info> | 2024-12-01 19:57:39 +0100 |
| commit | 11639a915b229952c267deb03a367ef70bb4a27e (patch) | |
| tree | 7a924e01fe494f18b129e32be02eab049a0b2fd1 | |
| parent | 0a038cd8f528a9ff92daddaa5bc4b432f4fbdc7c (diff) | |
Change Day15 Part 2 to not use do-notation.
| -rw-r--r-- | Day15.lean | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -109,14 +109,16 @@ where /- Funny, by the way, that the riddle only needs insert/remove, but not find... -/ -private def focussingPower (hashMap : HolidayAsciiStringHelperManualArrangementProcedure Substring (Fin 10)) : Nat := Id.run do - let mut totalPower := 0 - for h : boxIndex in [:hashMap.boxes.size] do - let mut lensIndex := 0 - for lens in hashMap.boxes[boxIndex] do - lensIndex := lensIndex + 1 - totalPower := totalPower + (1 + boxIndex) * lensIndex * lens.snd.val - totalPower +private def focussingPower (hashMap : HolidayAsciiStringHelperManualArrangementProcedure Substring (Fin 10)) : Nat := + Prod.fst $ + hashMap.boxes.foldl ( + λ(totalPower, boxIndex) box ↦ + let totalPower := Prod.fst $ box.foldl + (λ(totalPower, lensIndex) lens ↦ (totalPower + boxIndex * lensIndex * lens.snd.val, lensIndex + 1)) + (totalPower, 1) + (totalPower, boxIndex + 1) + ) + (0,1) private instance : HolidayAsciiStringHelperAble Substring where holidayAsciiStringHelper := holidayAsciiStringHelper 0 |
