summaryrefslogtreecommitdiff
path: root/Day3.lean
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2023-12-07 20:26:51 +0100
committerAndreas Grois <andi@grois.info>2023-12-07 20:26:51 +0100
commit8d6efb1c1fdddc1fbad167510ce25e56be684130 (patch)
treef35cf0d4943ccb397f3d0a91ad8a1cb1116eccdd /Day3.lean
parent9fb83b22220c825943549bc97bdab457bfad7f5b (diff)
Allow error messages in parsing (for debugging)
And fix an off-by-one in day 5
Diffstat (limited to 'Day3.lean')
-rw-r--r--Day3.lean4
1 files changed, 2 insertions, 2 deletions
diff --git a/Day3.lean b/Day3.lean
index 76c06be..e15e205 100644
--- a/Day3.lean
+++ b/Day3.lean
@@ -78,10 +78,10 @@ private def extractPartNumbers (input : List (Coordinate × Char)) : List PartNu
acc :: helper as none
helper input none
-def parse (schematic : String) : Option Schematic := do
+def parse (schematic : String) : Except String Schematic := do
-- I think this one is easier if we don't split the input in lines. Because:
let charsWithCoordinates ← match schematic.toList with
- | [] => none
+ | [] => throw "Could not pare input: Empty"
| c :: cs => pure $ cs.scan (λ s c ↦ (uncurry Coordinate.nextByChar s, c)) (Coordinate.default, c)
-- Whitespaces are **intentionally** left in. This makes extracting the numbers easier.
pure $ {