diff --git a/aoc/src/dev/ctsk/aoc/days/Day10.scala b/aoc/src/dev/ctsk/aoc/days/Day10.scala index b79bd22..0cad2c8 100644 --- a/aoc/src/dev/ctsk/aoc/days/Day10.scala +++ b/aoc/src/dev/ctsk/aoc/days/Day10.scala @@ -4,41 +4,29 @@ import dev.ctsk.aoc._ import dev.ctsk.aoc.Direction._ object Day10 extends Solver(10): - type Input = (Grid[Char], Seq[Point]) + type Input = Vector[(Point, Point)] def pre(input: os.ReadablePath): Input = val grid = Grid(os.read.lines(input).map(_.toArray).toArray) - val zero = grid.find(_ == '0').toSeq - (grid, zero) - def step( - grid: Grid[Char], - start: Seq[(Point, Point)], - height: Int - ): Seq[(Point, Point)] = - (for - (p, origin) <- start - a <- Seq(Up, Down, Left, Right) - if grid(a(p)).exists(_.asDigit == height) - yield (a(p), origin)) + def step(seq: Input, height: Int): Input = + (for + (p, origin) <- seq + a <- Seq(Up, Down, Left, Right) + if grid(a(p)).exists(_.asDigit == height) + yield (a(p), origin)).toVector - def part1(input: Input): Int = - val (grid, zero) = input - (1 to 9) - .foldLeft(zero.zip(zero)) { case (acc, h) => step(grid, acc, h) } - .distinct - .size + val zero = grid.find(_ == '0').toVector + (1 to 9).foldLeft(zero.zip(zero)) { case (acc, h) => step(acc, h) } - def part2(input: Input): Int = - val (grid, zero) = input - (1 to 9) - .foldLeft(zero.zip(zero)) { case (acc, h) => step(grid, acc, h) } - .size + def part1(input: Input): Int = input.distinct.size + + def part2(input: Input): Int = input.size def run(input: os.ReadablePath): (Timings, Solution) = - val (pre_time, (grid, zero)) = timed { pre(input) } - val (p1_time, p1_solution) = timed { part1((grid, zero)) } - val (p2_time, p2_solution) = timed { part2((grid, zero)) } + val (pre_time, pre_input) = timed { pre(input) } + val (p1_time, p1_solution) = timed { part1(pre_input) } + val (p2_time, p2_solution) = timed { part2(pre_input) } ( Timings(pre_time, p1_time, p2_time),