Day 25
This commit is contained in:
@@ -25,7 +25,8 @@ val solvers = Map[Int, Solver](
|
||||
20 -> Day20,
|
||||
21 -> Day21,
|
||||
22 -> Day22,
|
||||
23 -> Day23
|
||||
23 -> Day23,
|
||||
25 -> Day25
|
||||
)
|
||||
|
||||
def runSolver(solver: Solver, input: os.Path): Unit =
|
||||
@@ -36,7 +37,9 @@ def runSolver(solver: Solver, input: os.Path): Unit =
|
||||
println(solution.p2)
|
||||
case None =>
|
||||
println(f"=============================================================")
|
||||
println(f"Day ${solver.day}%02d ------------------------------------------------------")
|
||||
println(
|
||||
f"Day ${solver.day}%02d ------------------------------------------------------"
|
||||
)
|
||||
println(f"Prep ${timings.prep}%53s μs")
|
||||
println(f"Part 1 ${solution.p1}%40s ${timings.p1}%10s μs")
|
||||
println(f"Part 2 ${solution.p2}%40s ${timings.p2}%10s μs")
|
||||
|
||||
35
aoc/src/dev/ctsk/aoc/days/Day25.scala
Normal file
35
aoc/src/dev/ctsk/aoc/days/Day25.scala
Normal file
@@ -0,0 +1,35 @@
|
||||
package dev.ctsk.aoc.days
|
||||
|
||||
import dev.ctsk.aoc.*
|
||||
import collection.parallel.CollectionConverters.*
|
||||
|
||||
object Day25 extends Solver(25):
|
||||
override def run(input: os.ReadablePath): (Timings, Solution) =
|
||||
val (pre_time, (locks, keys)) = timed {
|
||||
os
|
||||
.read(input)
|
||||
.split("\n\n")
|
||||
.map(_.linesIterator.map(_.toArray).toArray.transpose)
|
||||
.partition(_(0)(0) == '#')
|
||||
}
|
||||
|
||||
def profile(lock: Array[Array[Char]]): (Array[Int], Int) =
|
||||
(lock.map(_.count(_ == '#')), lock.head.length)
|
||||
|
||||
def fits(size: Int, lock: Array[Int], key: Array[Int]): Boolean =
|
||||
lock.zip(key).forall((l, k) => l + k <= size)
|
||||
|
||||
def p1 = timed {
|
||||
val keyProfiles = keys.map(profile)
|
||||
locks
|
||||
.map(profile)
|
||||
.map((lock, size) =>
|
||||
keyProfiles.count((key, _) => fits(size, lock, key))
|
||||
)
|
||||
.sum
|
||||
}
|
||||
|
||||
(
|
||||
Timings(pre_time, p1._1, 0),
|
||||
Solution(Int.box(p1._2), "MERRY CHRISTMAS")
|
||||
)
|
||||
1
data/25.ans
Normal file
1
data/25.ans
Normal file
@@ -0,0 +1 @@
|
||||
3395
|
||||
3999
data/25.in
Normal file
3999
data/25.in
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user