File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
src/main/scala/eu/sim642/adventofcode2024 Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -8,16 +8,21 @@ object Day25 {
8
8
def isKey (grid : Grid [Boolean ]): Boolean =
9
9
grid.head.forall(identity)
10
10
11
+ def fits (key : Grid [Boolean ], lock : Grid [Boolean ]): Boolean =
12
+ key.correspondsGrid(lock)((k, l) => ! (k && l))
13
+
11
14
def countLockKeyFits (lockKeys : Seq [Grid [Boolean ]]): Int = {
12
15
val (keys, locks) = lockKeys.partition(isKey)
13
16
(for {
14
17
key <- keys
15
18
lock <- locks
16
- if key.correspondsGrid(lock)((k, l) => ! (k && l) )
19
+ if fits(key, lock )
17
20
} yield ()).size
18
21
}
19
22
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
21
26
22
27
lazy val input : String = scala.io.Source .fromInputStream(getClass.getResourceAsStream(" day25.txt" )).mkString.trim
23
28
You can’t perform that action at this time.
0 commit comments