diff --git a/src/main/scala/eu/sim642/adventofcode2023/Day23.scala b/src/main/scala/eu/sim642/adventofcode2023/Day23.scala index f5be1f19..cf1fe908 100644 --- a/src/main/scala/eu/sim642/adventofcode2023/Day23.scala +++ b/src/main/scala/eu/sim642/adventofcode2023/Day23.scala @@ -16,7 +16,7 @@ object Day23 { '<' -> Pos(-1, 0), ) - def longestHike(grid: Grid[Char]): Int = { + def longestHike(grid: Grid[Char], slopes: Boolean = true): Int = { val graphTraversal = new GraphTraversal[HikePos] with UnitNeighbors[HikePos] { override val startNode: HikePos = HikePos(Pos(1, 0), Set(Pos(1, 0))) // TODO: don't hardcode @@ -24,7 +24,7 @@ object Day23 { override def unitNeighbors(hikePos: HikePos): IterableOnce[HikePos] = { val HikePos(pos, path) = hikePos for { - offset <- if (grid(pos) == '.') Pos.axisOffsets else Seq(slopeOffsets(grid(pos))) + offset <- if (!slopes || grid(pos) == '.') Pos.axisOffsets else Seq(slopeOffsets(grid(pos))) newPos = pos + offset if grid.containsPos(newPos) if grid(newPos) != '#' @@ -49,6 +49,7 @@ object Day23 { lazy val input: String = scala.io.Source.fromInputStream(getClass.getResourceAsStream("day23.txt")).mkString.trim def main(args: Array[String]): Unit = { - println(longestHike(parseGrid(input))) + //println(longestHike(parseGrid(input))) + println(longestHike(parseGrid(input), slopes = false)) } } diff --git a/src/test/scala/eu/sim642/adventofcode2023/Day23Test.scala b/src/test/scala/eu/sim642/adventofcode2023/Day23Test.scala index 45a5bdef..80be501a 100644 --- a/src/test/scala/eu/sim642/adventofcode2023/Day23Test.scala +++ b/src/test/scala/eu/sim642/adventofcode2023/Day23Test.scala @@ -37,4 +37,12 @@ class Day23Test extends AnyFunSuite { ignore("Part 1 input answer") { // TODO: optimize assert(longestHike(parseGrid(input)) == 2414) } + + test("Part 2 examples") { + assert(longestHike(parseGrid(exampleInput), slopes = false) == 154) + } + + ignore("Part 2 input answer") { // TODO: optimize + assert(longestHike(parseGrid(input), slopes = false) == 2414) + } }