summaryrefslogtreecommitdiff
path: root/Day11.lean
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2024-09-19 00:14:18 +0200
committerAndreas Grois <andi@grois.info>2024-09-19 00:14:18 +0200
commit2ceb539bf306992e726280c24ce8d7b69e4c8b5e (patch)
tree3433e5bb28f65f475dcf2ee17544dc1ff2e0d612 /Day11.lean
parent2c1f2362c69ab20b10b61bdbebf8e5121eca38b1 (diff)
Day 11 Parsing
Diffstat (limited to 'Day11.lean')
-rw-r--r--Day11.lean36
1 files changed, 36 insertions, 0 deletions
diff --git a/Day11.lean b/Day11.lean
index d061e96..da36989 100644
--- a/Day11.lean
+++ b/Day11.lean
@@ -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