about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--day22202
-rw-r--r--day22.rkt171
2 files changed, 373 insertions, 0 deletions
diff --git a/day22 b/day22
new file mode 100644
index 0000000..0b70590
--- /dev/null
+++ b/day22
@@ -0,0 +1,202 @@
+                                                  ....#.......#.........#......#...............#...##......................#......#..........#....##..
+                                                  #.##.......#....#..#..................................#..................#..................#.......
+                                                  ........#................................#.......#.#...................#...#....#........#....#.....
+                                                  .........#.........##...........................##.......................#.....................#....
+                                                  ....#..#..#............#....#........#.#.#.....................#................#....#....#.........
+                                                  .............#.#.#..#.....#....#...............#.....#.......#.......#...........#..................
+                                                  ............#...#..#.....#......#..#.......#........##.#..............#.............................
+                                                  .................#.......#..#..........#......#....................................#.....#..........
+                                                  ......#..........#.......#.......#......#........#.................#.#....#...###..........#........
+                                                  ...#............................#.....#...................#..#.........#..............#....#........
+                                                  ...#..#..............#..................#.....#....#...............#.#....###.......#...#...#.......
+                                                  #...................#...#...........#....#..............#.......###.........#.............#.........
+                                                  .......#...........##......#.............#.........#.....................................#.......#.#
+                                                  ....#............#...............#...#...#.....#.#......#.....#..#.....##...................#.....#.
+                                                  ...............##.........#..#.#............................................#........#...#..........
+                                                  #...#...#.............#....#...##.........#.##........#......................#..........#......##..#
+                                                  ...........................#..............##............................#...........................
+                                                  .#........#........#.#.#..............#......................#........#.........#...................
+                                                  ...#.#...........#......#....................#...........##...........................#.............
+                                                  ...#..............#...#........###.##.......#.........................##.............#.#............
+                                                  .......#...#........#..........#........#.....#..................................................#..
+                                                  ................#.....##...........................###....#......#...#..............................
+                                                  ...........................#....................#.................................#...#.............
+                                                  .............#.....................#.#.........#...#.....#.......#..................................
+                                                  .#...#..................#....#...........#..#..#.#.....#......................#.....................
+                                                  #.........#...........................#...........#........#..................#..#.#.......####.##..
+                                                  ...#..#.....#..#......#...#..........#........#.......#..........#......#......#.........#..........
+                                                  .......#........#..........#.....#...#.#..#..........#.......#....#..#..#.....#.#.#....#..........##
+                                                  ..##.................#.#...#....#.##.......#...........#..........#..#........#..#..#.#.....#.#.....
+                                                  #.#.........................#.......#...........................#....................##....##..#....
+                                                  ..................#....##................#......#..#.............#..................................
+                                                  ...#.............##.....#.......................#...#............#..#....#..#........##....#........
+                                                  ..........#.............#.......................#.....................##............................
+                                                  #...#....#..........##............#..........###...#.............#.#........#..........#....#.......
+                                                  ..#.........................#......#.....#..................##....##.............................#..
+                                                  ............#.................#.................#..............#....#.......#..................#....
+                                                  .............................#.....#.#.#...##..#...................#.................#.........#....
+                                                  ...##.....#.#.##......#.#.....................#.....#..............#.#......#...................#...
+                                                  ........................................................#.#..........................##..#...#......
+                                                  ...................................#.........#.......#.......#.#...................#..#........#....
+                                                  .............................#.....#.....#.................#......#...#.....#..##...............#...
+                                                  .#..........#.....#..............#............#.........#.#......#.........#.................#......
+                                                  ......#.#..#.#.....#....#............#..........#........................#....##........#.........#.
+                                                  ....#............#......#...............#...........#.............#......................##.#...#...
+                                                  .........#.......#..#........................#.......##.#........#......#...............#.......#...
+                                                  .........#..............#....#...#............................#..#..........#.....#....#............
+                                                  .#.........#..........#............................#..................#..........................#..
+                                                  ........#.#.......#...........#........#.............................#.....#.#.#..............#..#..
+                                                  ...................................#.........#........#...#.......#..............#.........#....#...
+                                                  .#........#......................#.........................#......#.......#...........#....#........
+                                                  ....#...#..............##...........#......#......
+                                                  ..............#..........#........................
+                                                  ...............#....#..#.............#..#..#.#....
+                                                  .#.............#........................#.........
+                                                  #....................#.......#..#...............##
+                                                  ..#...............#....#...................###....
+                                                  ............#.....#.........#...........#....##...
+                                                  ......#.#...#..#.......#..........................
+                                                  ................................#....#............
+                                                  ............#......................#.#.......#.#..
+                                                  ......##......#..#.........#........#.........#.#.
+                                                  ..............#..............#.#.#.#...........#..
+                                                  ...............#..#..............................#
+                                                  .....................#................#.........#.
+                                                  ..........#..............................#.......#
+                                                  .........##......#..#....................#........
+                                                  .....#..#................#.......#..........##....
+                                                  .........#........#............#...#.#............
+                                                  #...#.....#.......#...............................
+                                                  ............................##...........##.......
+                                                  ............#...................................#.
+                                                  .............#..#.........#...........#...........
+                                                  ...............##.........#.........#.....#.......
+                                                  .............#.......#......#.........#...........
+                                                  ..##.......#..#...#.................##............
+                                                  ......#...#.......................................
+                                                  .#....#...........#......#.....#........#.........
+                                                  .#..#...........#......#...#......................
+                                                  ..........#..................#.............#......
+                                                  .....#.#..........##..................#....#......
+                                                  ...............#...#...............#..............
+                                                  ...........#....#...#.#..#..#.......#.............
+                                                  .....#..............#..............#........#.....
+                                                  ...................#.........................#.#..
+                                                  ..........##.............#.....................##.
+                                                  .............#.......#.........#.......##.........
+                                                  .....#..#....#......#.##.....#...........#........
+                                                  ...........#........#....#.....#.....#.#..#.......
+                                                  ...#............#...#.#..#.........#........#.....
+                                                  #.......#.........................................
+                                                  .........##.#....#.................#..#.........#.
+                                                  ..#....................................##.........
+                                                  .#......#........#...................#.#..........
+                                                  ......................#..#.............#.#........
+                                                  ......#...#...#...#............#.....##......#....
+                                                  #..#.#........#..............#.#.....#........#...
+                                                  .#.......#.................##...........#......##.
+                                                  ......................#..#........................
+                                                  ...#....#......#....#......#......##...........#..
+                                                  ......#.....#.....#..#........#....#..............
+....#...#...........#......................##...##........#.....#....#........................#...#.
+............##...#............#...#...............................#.................................
+.....#.................#................#.............#..................#..#...#......#.....#.#....
+.#..............#...............#.#...............#.....#.#..............#.#.....#.........#......#.
+.....#...##......#...#..............#................................##.#.#....#.#.......#...#......
+...........##........#.....#........#..#........................##..........#......#.##........#..#.
+...........#......#..#.....#.........................##....#.....#......#.............#.....#.......
+.....................##....#..#......#...................#........#.#....#........#..#..............
+#..........#...........#........................................#..............#.......##........#..
+........#..#.........................#......#...#...#........#.....................##...............
+..##.....#..............................................#...................#..........#.#..........
+.........#.......##.......................#.........###....................##......#..............#.
+..............#..............##.#..............#................#.....#.............................
+#............#.........#.#..#.................#...............#........#.....................#......
+...........#....#...........#....#............................#.................#.........#.........
+...#................................................#.#.....#....#.........#.........#.....##.....#.
+#..............#............#...#...#....#..#..............##......#.#...........#.#.........#......
+................#.......#...............#.....#...........#.........#...............................
+....#..#.........#..#...................#.##...##.............#.......#........#.................#..
+...........#.................#...........##..............##.....................#...............#...
+...#........................#.........#..#.......#.........#.................#..#..#................
+..#...............#.......#.........#...............#....................#..........................
+.#...............................#.#..........#................#............#...#.........#..#......
+#..#.........#.....#.........#.........................................#....#..............#....#.#.
+...............................##...........#...#................#......#...............#..#........
+......................................##...##......#..........#.........#..#.............#.#........
+...............#......#....#...................#....#.#................#......#...#...............#.
+.................#........#..#...#...#.............#......##......#....#.#.....#...#................
+..............................#.............................##...............................#......
+..#............#...#....#.......#..#.................#...#......#..##..#.#..#.....#..........#......
+#..............#........#....#..#.#.....##.......................##............................#....
+....................#..#............#................................#...........#...#..............
+................#.#..................................#.......#...#.....#...#........................
+..........#..........#.......#....#.......#.#....................#....#.................#..........#
+..............#.................#.................#.......#.......#......#..#...................#...
+................#.#.........#.##...#....#......#.........#...................###.#.........#........
+#..........#...........#.............#...#...........................#..##..#.......................
+..........#.............##.......#.........#........#...#.#.......#...................#........#....
+..#.........#...........................#.#.#.........#....................................#........
+..#.........#............................#...........#...#...................#......................
+....#.......#...#.........#....#.............................#......##..#........................#..
+....#..........................#...............#...#.....#...#...................#............#.....
+.....#....#........#.......#..#.#............#..#...........#..##.............#..........#..........
+........#......#..#...........#.............................#..........#.....#....................##
+#..............#..#...#................#................................#.#...................#.#...
+..#...........................#.#...........#.#............#...................#....#....#...##.....
+.................#.................#...............#.....#........#..........................#..##..
+...............#........#.............#..............#..#.....#.....#........................#......
+.............#......#.................#..............#...#........#...#...#................#......#.
+.....#........#..#.....#............#....#.....#............#.......................................
+......#.........#.......##..#............#....#...
+...........#.........#....#....#.................#
+.....#......##................#.##................
+...#........#.#.....#.#..............#......#.....
+......##.#.#...........#....#...#.......#......#.#
+.#......##..##..........#.........#.............#.
+.##....#....#....................#................
+...#......##............#..........#...##..#......
+..##......##..................#........#..........
+...#........#...#.#..................#............
+.......................#.......#..................
+....................................#.............
+.............#.....#.#...............#........#...
+............#..#...#........................#.....
+.................#...............#..#.............
+..................................#.#.............
+..#.............#.#........#......................
+.#.....................#..........................
+......##.#..........................#.............
+..................#.................#....#.......#
+...#....#..#..#...........................#....#.#
+........#..................#.#....................
+............................#.............#.#.....
+#.....#...#.......#..#.......#....................
+.......................................#..#.....#.
+......#...........#................#....#.....#...
+......#.........#.........#..#..............#....#
+.....##.......#.#..................#..............
+.#.#..#...#........#..............#........#....#.
+.........#..............#.........................
+..#......#........................#...#...#.......
+.................#.....#.....#....................
+.#.......#......#...#.......#.....###......#......
+#............#.....#..............................
+#.......#..........#.....................#......#.
+....#......#...........................#...#......
+....#....#.....................#.....#............
+........#.....................#...........##......
+#...........#......#.#..#....#..#.................
+................#.................#...............
+............#.........#.....#......#..#.........#.
+.....#.....#.................#......#.............
+............#...#......##................#........
+.#......#...........#.......#.#........##.........
+.......#.......................................#..
+....#..............#.......#........#......#......
+........#............#.....##..........#..........
+........#...........#.............#...............
+.........#.........#.......#......................
+#...#.##..................................#.......
+
+37R23L11R49R12R47R21R39R36L27R9L48L11R2L18R30R2L37R28L43R6R19R19R28L31L34R18R24L4R33R15R35L5R11R4R21R42L41L8R49R13R31L8R21L18R22L23R4R12L13R9R42L32L38L21L28R37R32L39L33L4L25L26L14R43L15L43R50L37L38L37L3L38R29L36R3R11R3R29L39R17L45L49R3R21R36R26L13R50L35L33R26R9L29L39R1R42R47L42L5R17R33R21L14R40R18R14R27R5R12L46L7R47R27L20L39R26L17R12L39R32L23L24R48R34R39L30R43R15R15R33L9R28L10R28L34L4R25L23R4L45L39R20R48R36L17R30R26R32R16R27L37L18L33R21L4R21L11R32R10R36L23R25R8L32R26R35L28L30L16L41L39R31L30R6L33L10R8R34L22R8R35R40R33R31L30L21R32L26R9R21R22L35R45R28R42L24R7L33R43R11L22R44L10L9R42L9L49L42R2L16L49R28L2L9L34L16L33R8L37L7L8R5R32R7L8L36R41L1R8L5L8L17R23R19L15R16L50R35L42L14L48L29R42R47R29R11R29L30L5R26L46L38R16L41L29R30L33R24L20L47R33L8L33L44L45R37L22R2L25L5R24R48R44R48L2R42R46R34R40R50R15R10L12R23L49L47R3L2L48L7R49L34L20R26R25L29R24L43R38L47R18R31R41R44R49L33R24R18L38R35R3R39R46L28R43R30L33L40R17R38R2L12R28R29R40L27R19L19L25R5L44R6L15L7L8L31R14R13R24R22R48R50R50L29L30L37R36L38L3R28R45R25L4R14L26R17L1L38R16L14R31L27R29L6L42L11L49L35L13L22L36R25R44L31R2R9R36R6L27R38R21L21L28R46R12L32R34R38R23R33L39R11L40L21R2L12L46R13R7L3R4R1R22L9R43L34L37L38R30L40R3R11L15L50R27R10R43L38R27L34R22R26L47R18L23R1L8R50L29L12R12L47L33R19R43R28L7R24L6L7R36R33R22L3L11R48L10R5L44R27R46R8L3L38R16R30R1L26R6R48L49R15L11R41L16L48L41L16R41L46L18R19L17L16L5R21R50L49R29L48R23L7L33R47L24L19L29R11L30R18R13L33L29R44L14L42L27R4R34L22R10R50L41R40L18L31L31R43R47L44R28R14L44R40L35R10R16L30R28R48L46L33R11R1L37R50L3R11L48R47R25R49L17R35L10R43L22L8L50R37L30L49R5R16L36L4R18R21L13L47L32L12R29R2L11L34L19L39L45R10L33L5L24R10L42R4L48L37L11L14R5R39R25L42R33L48R10R16L42R33R6R19L16R27L25R27R37R48R49R9L29L47L36L42R31R42L49R32R2L39L2L6R21L1L21L6R1L50L45R16R6L50L45R40L49L16L29L48R13L35L43R5L11L47R45R7R28L35L43R45R42R23R34L49L2R49R30R39L17R25L31R10L45R10L15R40L1R42L39L16L26R33R34L30L13R26L41R33R43L25L8R11R17R21L25L1L45R1L25L21L16L25L26R35R45R35L15R27R8R25R11R30R37R46L5R25R1L31R3R3L16L48R37L46R30L44R39L2L8L46R28L48R38R45L26L28L23R41R13R6R49L11L34R36L14L39L45L6L13L44L40L29R37L6L45R33L22L12R12L34L4R47L18R29R16L31R1R12L12R10L47L43R40L16R16R44L24R31R4R13L2L47L29L41R37L44R26R47L21L47R48L39R43L38R1L44L25R5L34R39R18R26L49R9L33L19L32R48L39L18R24L31L45L46L14L45R47L45L35L3L49R25L21L49L49L1L38L12R48R46L33R6R31R19L31R24L37R27L34R17L50R38R22L11L9L15L21L31L22R32L26R4L44L2L42R32L31L44L40R24L48R36L50R20R3L33R31L20L46R47R27R43L5L18R43R8R38L46L36L7L22R32L8L16L1R35L41R45R18R50L25R41R7L18R13L37R38L41R18R14R25R26L48L5R41R20L18L40L41L16R40R40L8R13L7L41R10L33R3R7L11L27R34R1R29L20L20R7L42L34L19L43L19L47R21L43R50R7L44R44L5L12L12L5L49L14L46R14L24R8R30R25R43L35R12R36L47L36L49L36R42R19L1L15L18L43R14L45R38L17R14R8L8L22R46R3L46R8R34L5R26L44L49R45R3R13R5L9R6L24L24L4L8L25R15R16L33L18R14L49R10R2R25L6R4R36R20L40R11L17L18R36R16R27L1R1R22L27R10L9L45L12R3L1L44L32R10L37L40L40L9L5R10L29R33R4R19L15R41L15R17R36R1R13R9R40L26L38R21L23L50L6L49R22L18L25L42L3L50R10L32L35L42L49R28R44L33L20R3R13R46L27L3L31R19L17L42L18R17R42L26L1R50R24R16R3L36R41L45R29R49R2R35L48R15R41L16L45L41L5R3R20R10L38R47R36R27L7L1R13L44L35L36L45L32R23R24R25L24L3L22L46L21L33L37R22L18L15L21L25R49L26R42R16R28R1L47L27L10R41R50L28R24L30L17R17L22R43R28R40L38R36R13R49R35R43R31L31R9R41R24R18R33R24R16L31L1R2R19L45L40L3R33L9R20R48L43R15R15R15L4L3R15L36R25R37R36L32L14L32R18R4L48R16R30R24L49L27L40R13L3L42R8R45R32R1R42L6L13L43L10R28R16L5R27R31R49L50L35R7R8L23L2L33L22L42R24L14L13L34R25R5L37R29R15R44R39R13R15R1R23L42L3R15L37L18L8R45L40L41R49L44L34R22R23R12L16R40R48L32R6L8L36L32R37R49R23L18L41L3R7L26L49L34L40R46L42L5L30R42R49L36R12L8L6L49R29R33R31R27R40R19L3R38R38R16R45L2L20L3R18R18L22R33R5R32L36L36L6L43R3L18R33L31L49R44L35R29L6L26R2R3L26L33R7R30R35R2L33L39L49L1L3R50R5R13L43L7R8L16R16R1R28R9L15R32L5L24R44R2R37L46L21L29R1L24L21L46R31L25R32R11L48L29L1R6L7R47R36R19R18L18L48R44L20L17L13L18L49R5R45R48L24R23R11L15L31R27R28L2R11L36L6R42L2R42R31R36R16L4L8R16L28R15L4R35R39L42L27R13L25R5R32L23R25L22L24L23L15R8L37L38R23R45R5R4R8L7L14L26L48L15L39L37R17R35R13R7R38L28L43R22L28R39L35R9R3R22R43L25R11R34R39L42L35R23R18R8R6R49R42R6L50L4L20R34L16L27R44L1R14L26R48L28R39R18L35R23R33R2R1R34L18R46R24R42L44L17L48R13R16L2L41L16L21L29L31L2R47R44L32L9L36R13R5L3L17R8R43L48L30R40L8L38L34L47R16R8R9R29L42R34L41L33L16R36L37L40R27R24L31L42L12L32L20L25L45L28L13L4R39R13L30R25R50R7L9L9L17R16R31R6R38L28L33R15R40L32R45R49L35L32L8R35L28L1R31R9L16L34R39L18L29L44R40L35R37L49L27R30L11L25R10R45R24R34R22R21R17L8L15R9R17R19R14L15L34L15R33R27L50R42L1L26R11L27R2L23R26R40L40L16L33L18R8R6L8L24R3R31R5L25R13R9L45R28L28R36L32R30L16R33R38L32L49R27L48L34L9L17L49L14R17L20R7L6L26L42L50L24R43R48R50R34R22R31L32R44L26L9L50R25R24R3R23R5L31L21L17L4R46L30L3L7L8R38R30R39R37R40R11L38R43R26L32R16R39L17R39R1R50R12R49L18R2R33L47L30R20R42L6R48R38R41L12R30R17L32L40L36L45R22R7R44R17L14R27L39R30L1R29R1R39L5R30L1R2R1L20L32L44L5L34L9L5L28R37R36R41L47L25L25L45R14L35R44R33R12R30L25L43L4L45L46L22R18R15R38R5L37L44L7L36L22L29L33R43R17L11R13L18R7R10L43R47L20L1R34L13L35L37L31R41R39L45R35L23R44R33L20R49L6L3L46L38L20L16L12R6R50R30R34R39R15R3L5R20R16R18L31R2L44L41R44L40R31R3R19R33R49R20R39L32L7R18L14L29L30L26L28R50R4R9R20L25R16R45L28L40L2L15R13L43L40R50R33R18L45R15R20L36R39L30L22R12L33R6R5R2L37L6R16R2R34L47R15R11L23L37R20L1R17R8L28R21R18R48L18L29L34R30R15R6R45R15L26R28L41L13R47L18R35R3R41L25R16L11R27R49R9L15R38R49L20L30R5R8L31R39R4L32L45R30L30L12L18L10R44L39L36L48L29R8L9L50L31L11R20R26L27R16R5L49R45L12R27R32R34L39L25L40R18L35L33L35R45L36L37R31R32R8L21R40L29L49R12R25L28R21L23R30R10R44R19L47R46R8R16R35R12L30R26R41R20R46L48L7L16R4R30L45R38R21L3L50L23R48R22R13R1L2L6R45R25L2L6L25L19R5L42R7R41R24R50R30R18R43L25R30L8L29R4R39L50R49L18R45R33L34R45R35R17L10R49L1R13R48R12R37L26
diff --git a/day22.rkt b/day22.rkt
new file mode 100644
index 0000000..24bcf17
--- /dev/null
+++ b/day22.rkt
@@ -0,0 +1,171 @@
+#lang racket
+
+;; https://github.com/progheal/adventofcode/blob/master/2022/22.cpp
+
+(define-values (field path)
+  (let-values ([(field path) (splitf-at (file->lines "day22") (lambda (line) (not (equal? line ""))))])
+    (let ([max-line (+ 1 (apply max (map string-length field)))])
+      (values (for/vector ([line (append field (list ""))])
+                (for/vector ([char (~a line #:min-width max-line)])
+                  char))
+              (for/list ([step (regexp-match* #rx"[0-9]+|." (second path))])
+                (or (string->number step) step))))))
+
+;; field
+;; path
+
+(define (vector-index-of v e)
+  (let loop ([i 0])
+    (if (>= i (vector-length v))
+      #f
+      (if (equal? (vector-ref v i) e)
+        i
+        (loop (+ i 1))))))
+
+(define dir #(0 1 0 -1 0))
+
+(define (do-step x y d)
+  (values (modulo (+ x (vector-ref dir d))
+                  (vector-length field))
+          (modulo (+ y (vector-ref dir (+ d 1)))
+                  (vector-length (vector-ref field 0)))
+          d))
+
+(define (turn-left d)
+  (modulo (- d 1) 4))
+
+(define (turn-right d)
+  (modulo (+ d 1) 4))
+
+(define (walk field path)
+  (define d 0)
+  (define x 0)
+  (define y (vector-index-of (vector-ref field x) #\.))
+
+  (for ([step path])
+    (match step
+      ["L" (set! d (turn-left d))]
+      ["R" (set! d (turn-right d))]
+      [n (let loop ([n n])
+           (when (> n 0)
+             (let ([px x]
+                   [py y]
+                   [pd d])
+               (let loop2 ()
+                 (set!-values (x y d) (do-step x y d))
+                 (when (equal? (vector-ref (vector-ref field x) y) #\space)
+                   (loop2)))
+               (if (equal? (vector-ref (vector-ref field x) y) #\#)
+                 (set!-values (x y d) (values px py pd))
+                 (loop (- n 1))))))]))
+
+  ; (list x y d)
+  (+ (* 1000 (+ x 1)) (* 4 (+ y 1)) d)
+)
+
+
+(walk field path)
+;; 13566
+
+
+(define cube-edge (make-hash))
+
+(define d 0)
+(define x 0)
+(define y (vector-index-of (vector-ref field x) #\.))
+
+(define cube-size (gcd (- (vector-length field) 1)
+                       (- (vector-length (vector-ref field 0)) 1)))
+
+(displayln (list "cube size:" cube-size))
+
+(let ([reverse false]
+      [unmatched-edge '()]
+      [unmatched-turn (list 1)]
+      [ex x]
+      [ey y]
+      [ed d]
+      [ignore 42]
+      )
+  (let loop ()
+    (if reverse
+      (for ([i (in-range 0 cube-size)])
+        (let-values ([(rx ry rd) (apply values (car unmatched-edge))])
+          (set! unmatched-edge (cdr unmatched-edge))
+          (hash-set! cube-edge
+                     (vector rx ry (turn-left rd))
+                     (vector ex ey (turn-right ed)))
+          (hash-set! cube-edge
+                     (vector ex ey (turn-left ed))
+                     (vector rx ry (turn-right rd)))
+          (set!-values (ex ey ed) (do-step ex ey ed))))
+      (for ([i (in-range 0 cube-size)])
+        (set! unmatched-edge (cons (list ex ey ed) unmatched-edge))
+        (set!-values (ex ey ed) (do-step ex ey ed))))
+    (let*-values ([(now) (vector-ref (vector-ref field ex) ey)]
+                  [(lx ly ld) (do-step ex ey (turn-left ed))]
+                  [(myleft) (vector-ref (vector-ref field lx) ly)]
+                  [(edge-turn) -1])
+      (cond [(and (equal? myleft #\space) (equal? now #\space))
+             (set! edge-turn 1)]
+            [(and (equal? myleft #\space) (not (equal? now #\space)))
+             (set! edge-turn 0)])
+      (if reverse
+        (let ([last-unmatched-turn (car unmatched-turn)])
+          (if (= 1 (+ last-unmatched-turn edge-turn))
+            (begin
+              (set! unmatched-turn (cdr unmatched-turn))
+              (when (null? unmatched-turn)
+                (set! unmatched-turn (cons edge-turn unmatched-turn))
+                (set! reverse #f)))
+            (begin
+              (set! unmatched-turn (cons 0 (cdr unmatched-turn)))
+              (set! reverse #f))))
+        (if (= edge-turn -1)
+          (set! reverse #t)
+          (set! unmatched-turn (cons edge-turn unmatched-turn))))
+
+      (cond [(= edge-turn 1)
+             (set! ed (turn-right ed))
+             (set!-values (ex ey ignore) (do-step ex ey (turn-right ed)))]
+            [(= edge-turn -1)
+             (set! ed (turn-left ed))
+             (set!-values (ex ey ignore) (do-step ex ey ed))]))
+
+    (unless (and (equal? ex x) (equal? ey y) (equal? ed d))
+      (loop)))
+  )
+
+
+;; cube-edge
+
+(define (do-cube-step x y d)
+  (if (hash-has-key? cube-edge (vector x y d))
+    (vector->values (hash-ref cube-edge (vector x y d)))
+    (do-step x y d)))
+
+(define (walk2 field path)
+  (define d 0)
+  (define x 0)
+  (define y (vector-index-of (vector-ref field x) #\.))
+
+  (for ([step path])
+    (match step
+      ["L" (set! d (modulo (- d 1) 4))]
+      ["R" (set! d (modulo (+ d 1) 4))]
+      [n (let loop ([n n])
+           (when (> n 0)
+             (let ([px x]
+                   [py y]
+                   [pd d])
+               (set!-values (x y d) (do-cube-step x y d))
+               (if (equal? (vector-ref (vector-ref field x) y) #\#)
+                 (set!-values (x y d) (values px py pd))
+                 (loop (- n 1))))))]))
+
+  ; (list x y d)
+  (+ (* 1000 (+ x 1)) (* 4 (+ y 1)) d)
+)
+
+(walk2 field path)
+;; 11451