Skip to content

Commit 326a6c8

Browse files
committed
Clean up 2024 day 25
1 parent 8811f45 commit 326a6c8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/scala/eu/sim642/adventofcode2024/Day25.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ object Day25 {
88
def isKey(grid: Grid[Boolean]): Boolean =
99
grid.head.forall(identity)
1010

11+
def fits(key: Grid[Boolean], lock: Grid[Boolean]): Boolean =
12+
key.correspondsGrid(lock)((k, l) => !(k && l))
13+
1114
def countLockKeyFits(lockKeys: Seq[Grid[Boolean]]): Int = {
1215
val (keys, locks) = lockKeys.partition(isKey)
1316
(for {
1417
key <- keys
1518
lock <- locks
16-
if key.correspondsGrid(lock)((k, l) => !(k && l))
19+
if fits(key, lock)
1720
} yield ()).size
1821
}
1922

20-
def parseLockKeys(input: String): Seq[Grid[Boolean]] = input.split("\n\n").map(_.linesIterator.map(_.map(_ == '#').toVector).toVector).toSeq
23+
def parseLockKey(s: String): Grid[Boolean] = s.linesIterator.map(_.map(_ == '#').toVector).toVector
24+
25+
def parseLockKeys(input: String): Seq[Grid[Boolean]] = input.split("\n\n").map(parseLockKey).toSeq
2126

2227
lazy val input: String = scala.io.Source.fromInputStream(getClass.getResourceAsStream("day25.txt")).mkString.trim
2328

0 commit comments

Comments
 (0)