Skip to content

Commit

Permalink
Clean up 2024 day 25
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Dec 25, 2024
1 parent 8811f45 commit 326a6c8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/scala/eu/sim642/adventofcode2024/Day25.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ object Day25 {
def isKey(grid: Grid[Boolean]): Boolean =
grid.head.forall(identity)

def fits(key: Grid[Boolean], lock: Grid[Boolean]): Boolean =
key.correspondsGrid(lock)((k, l) => !(k && l))

def countLockKeyFits(lockKeys: Seq[Grid[Boolean]]): Int = {
val (keys, locks) = lockKeys.partition(isKey)
(for {
key <- keys
lock <- locks
if key.correspondsGrid(lock)((k, l) => !(k && l))
if fits(key, lock)
} yield ()).size
}

def parseLockKeys(input: String): Seq[Grid[Boolean]] = input.split("\n\n").map(_.linesIterator.map(_.map(_ == '#').toVector).toVector).toSeq
def parseLockKey(s: String): Grid[Boolean] = s.linesIterator.map(_.map(_ == '#').toVector).toVector

def parseLockKeys(input: String): Seq[Grid[Boolean]] = input.split("\n\n").map(parseLockKey).toSeq

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

Expand Down

0 comments on commit 326a6c8

Please sign in to comment.