diff options
| author | Andreas Grois <andi@grois.info> | 2024-09-19 00:14:18 +0200 |
|---|---|---|
| committer | Andreas Grois <andi@grois.info> | 2024-09-19 00:14:18 +0200 |
| commit | 2ceb539bf306992e726280c24ce8d7b69e4c8b5e (patch) | |
| tree | 3433e5bb28f65f475dcf2ee17544dc1ff2e0d612 /Day11.lean | |
| parent | 2c1f2362c69ab20b10b61bdbebf8e5121eca38b1 (diff) | |
Day 11 Parsing
Diffstat (limited to 'Day11.lean')
| -rw-r--r-- | Day11.lean | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -1,3 +1,39 @@ import «Common» namespace Day11 + +inductive Pixel +| void +| galaxy + +instance : ToString Pixel where + toString := λ + | .void => "." + | .galaxy => "#" + +structure ParseCharError where + foundChar : Char + +instance : ToString ParseCharError where + toString := λx ↦ s!"Invalid character. Expected '#' or '.', but found {x.foundChar}" + +def parseCharacter : Char → Except ParseCharError Pixel +| '.' => Except.ok Pixel.void +| '#' => Except.ok Pixel.galaxy +| foundChar => Except.error {foundChar} + +------------------------------------------------------------------------------------------ + +private def testData := "...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#..... +" + +#eval Parsing.RectangularGrid.ofString parseCharacter testData |
