diff options
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 |
