File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -33,9 +33,17 @@ def findOrderedIndices(input: String): Int =
3333
3434def findDividerIndices (input : String ): Int =
3535 val dividers = List (" [[2]]" , " [[6]]" ).map(readPacket)
36- val packets = List .from(input.linesIterator.filter(_.nonEmpty).map(readPacket))
37- val indices = (dividers ++ packets).sorted.zipWithIndex.map((key, value) => key -> (value + 1 )).toMap
38- dividers.map(indices(_)).product
36+ val lookup = dividers.toSet
37+ val packets = input
38+ .linesIterator
39+ .filter(_.nonEmpty)
40+ .map(readPacket)
41+ val indices = (dividers ++ packets)
42+ .sorted
43+ .iterator
44+ .zipWithIndex
45+ .collect { case (p, i) if lookup.contains(p) => i + 1 }
46+ indices.take(2 ).product
3947
4048enum Packet :
4149 case Nested (packets : List [Packet ])
You can’t perform that action at this time.
0 commit comments