File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ package `2024` .day25
2+
3+ import prelude .*
4+
5+ enum Scheme (xs : Vector [Int ]):
6+ case Lock (xs : Vector [Int ]) extends Scheme (xs)
7+ case Key (xs : Vector [Int ]) extends Scheme (xs)
8+
9+ export Scheme .*
10+
11+ extension (l : Lock )
12+ inline infix def isMatching (k : Key )(using height : Int ): Boolean =
13+ (l.xs zip k.xs).forall((x, y) => x + y <= height)
14+
15+ def parse (input : String ): Scheme =
16+ val lines = input.split('\n ' ).toVector.transpose
17+ val xs = lines.map(_.count(_ == '#' ))
18+ if lines.head.head == '#' then Lock (xs) else Key (xs)
19+
20+ @ main def main () =
21+ val input = fromFile(" .cache/2024/25.txt" ).mkString.trim
22+ val xs = input.split(" \n\n " ).toVector
23+
24+ given height : Int = xs.head.linesIterator.size
25+
26+ val (locks, keys) = xs.map(parse).partitionMap {
27+ case lock : Lock => Left (lock)
28+ case key : Key => Right (key)
29+ }
30+ val combos = locks.flatMap(l => keys.filter(l.isMatching))
31+ println(combos.size)
You can’t perform that action at this time.
0 commit comments