diff --git a/src/main/scala/org/lemon/advent/year2024/Day17.scala b/src/main/scala/org/lemon/advent/year2024/Day17.scala index 93f1687..1621ab3 100644 --- a/src/main/scala/org/lemon/advent/year2024/Day17.scala +++ b/src/main/scala/org/lemon/advent/year2024/Day17.scala @@ -99,9 +99,9 @@ private object Day17: // the program output depends on the length of A in octal // assumption is that the most significant tribit of A relates to the last output - program.tails.toSeq.reverse.drop(1).foldLeft(Seq(0L)) { (acc, tail) => + program.reverse.foldLeft(Seq(0L)) { (acc, ele) => acc.flatMap(a => - (a * 8 until (a + 1) * 8).filter(a => execute(initialState(a, b, c, program)).output == tail) + (a * 8 until (a + 1) * 8).filter(a => execute(initialState(a, b, c, program)).output.head == ele) ) } .min