From abee20f298686fb8ccd49fff6c512ac5ac39b730 Mon Sep 17 00:00:00 2001 From: nmcb Date: Sat, 1 Aug 2026 09:37:27 +0200 Subject: [PATCH 1/3] cleanup --- 2017/src/main/scala/aoc2017/Day25.scala | 33 +++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/2017/src/main/scala/aoc2017/Day25.scala b/2017/src/main/scala/aoc2017/Day25.scala index 545968e9..76f268f8 100644 --- a/2017/src/main/scala/aoc2017/Day25.scala +++ b/2017/src/main/scala/aoc2017/Day25.scala @@ -3,6 +3,8 @@ package aoc2017 import nmcb.* import nmcb.predef.* +import scala.collection.Iterator.iterate + object Day25 extends AoC: enum Move derives CanEqual: @@ -11,7 +13,7 @@ object Day25 extends AoC: import Move.* - type State = String + type State = Char type Value = Int type Position = Int type Tape = Map[Position, Value] @@ -82,22 +84,21 @@ object Day25 extends AoC: * - Continue with state E. * */ - val beginState: State = "A" - val steps: Int = 12317297 + val beginState: State = 'A' val transitions: Transitions = Map( - ("A", 0) -> ("B", 1, R), - ("A", 1) -> ("D", 0, L), - ("B", 0) -> ("C", 1, R), - ("B", 1) -> ("F", 0, R), - ("C", 0) -> ("C", 1, L), - ("C", 1) -> ("A", 1, L), - ("D", 0) -> ("E", 0, L), - ("D", 1) -> ("A", 1, R), - ("E", 0) -> ("A", 1, L), - ("E", 1) -> ("B", 0, R), - ("F", 0) -> ("C", 0, R), - ("F", 1) -> ("E", 0, R), + ('A', 0) -> ('B', 1, R), + ('A', 1) -> ('D', 0, L), + ('B', 0) -> ('C', 1, R), + ('B', 1) -> ('F', 0, R), + ('C', 0) -> ('C', 1, L), + ('C', 1) -> ('A', 1, L), + ('D', 0) -> ('E', 0, L), + ('D', 1) -> ('A', 1, R), + ('E', 0) -> ('A', 1, L), + ('E', 1) -> ('B', 0, R), + ('F', 0) -> ('C', 0, R), + ('F', 1) -> ('E', 0, R), ) case class Turing( @@ -124,4 +125,4 @@ object Day25 extends AoC: def turing: Turing = Turing(transitions, beginState) - override lazy val answer1: Int = Iterator.iterate(turing)(_.step).nth(steps).tape.count(_.right == 1) + override lazy val answer1: Int = iterate(turing)(_.step).nth(12317297).tape.count(_.right == 1) From b9ba97dd002a4a7d2fdf5eec58c17567140788dc Mon Sep 17 00:00:00 2001 From: nmcb Date: Sat, 1 Aug 2026 12:09:23 +0200 Subject: [PATCH 2/3] cleanup --- 2017/src/main/scala/aoc2017/Day25.scala | 48 +++++++++---------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/2017/src/main/scala/aoc2017/Day25.scala b/2017/src/main/scala/aoc2017/Day25.scala index 76f268f8..5b38696b 100644 --- a/2017/src/main/scala/aoc2017/Day25.scala +++ b/2017/src/main/scala/aoc2017/Day25.scala @@ -7,17 +7,12 @@ import scala.collection.Iterator.iterate object Day25 extends AoC: - enum Move derives CanEqual: - case L - case R - - import Move.* - type State = Char type Value = Int + type Move = Int type Position = Int type Tape = Map[Position, Value] - type Transitions = Map[(State, Value), (State, Value, Move)] + type Transitions = Map[(from: State, read: Value), (write: Value, move: Move, to: State)] /** * Begin in state A. @@ -87,18 +82,18 @@ object Day25 extends AoC: val beginState: State = 'A' val transitions: Transitions = Map( - ('A', 0) -> ('B', 1, R), - ('A', 1) -> ('D', 0, L), - ('B', 0) -> ('C', 1, R), - ('B', 1) -> ('F', 0, R), - ('C', 0) -> ('C', 1, L), - ('C', 1) -> ('A', 1, L), - ('D', 0) -> ('E', 0, L), - ('D', 1) -> ('A', 1, R), - ('E', 0) -> ('A', 1, L), - ('E', 1) -> ('B', 0, R), - ('F', 0) -> ('C', 0, R), - ('F', 1) -> ('E', 0, R), + (from = 'A', read = 0) -> (write = 1, move = +1, to = 'B'), + (from = 'A', read = 1) -> (write = 0, move = -1, to = 'D'), + (from = 'B', read = 0) -> (write = 1, move = +1, to = 'C'), + (from = 'B', read = 1) -> (write = 0, move = +1, to = 'F'), + (from = 'C', read = 0) -> (write = 1, move = -1, to = 'C'), + (from = 'C', read = 1) -> (write = 1, move = -1, to = 'A'), + (from = 'D', read = 0) -> (write = 0, move = -1, to = 'E'), + (from = 'D', read = 1) -> (write = 1, move = +1, to = 'A'), + (from = 'E', read = 0) -> (write = 1, move = -1, to = 'A'), + (from = 'E', read = 1) -> (write = 0, move = +1, to = 'B'), + (from = 'F', read = 0) -> (write = 0, move = +1, to = 'C'), + (from = 'F', read = 1) -> (write = 0, move = +1, to = 'E'), ) case class Turing( @@ -109,19 +104,8 @@ object Day25 extends AoC: ): def step: Turing = - - val (nextState, nextValue, move) = - transitions((state, tape(cursor))) - - val nextCursor = - move match - case L => cursor - 1 - case R => cursor + 1 - - val nextTape = - tape + (cursor -> nextValue) - - copy(state = nextState, cursor = nextCursor, tape = nextTape) + val transition = transitions((from = state, read = tape(cursor))) + copy(state = transition.to, cursor = cursor + transition.move, tape = tape.updated(cursor, transition.write)) def turing: Turing = Turing(transitions, beginState) From 8e83fb93ed83ab7d25f8d7603b6c7d8d738e2e8b Mon Sep 17 00:00:00 2001 From: nmcb Date: Sat, 1 Aug 2026 12:14:22 +0200 Subject: [PATCH 3/3] fix merge conflicts --- 2017/src/main/scala/aoc2017/Day25.scala | 6 ------ 1 file changed, 6 deletions(-) diff --git a/2017/src/main/scala/aoc2017/Day25.scala b/2017/src/main/scala/aoc2017/Day25.scala index 11c4c65f..5b38696b 100644 --- a/2017/src/main/scala/aoc2017/Day25.scala +++ b/2017/src/main/scala/aoc2017/Day25.scala @@ -5,12 +5,6 @@ import nmcb.predef.* import scala.collection.Iterator.iterate -object Day25 extends AoC: - - enum Move derives CanEqual: - case L - case R - object Day25 extends AoC: type State = Char