@@ -4,26 +4,26 @@ import eu.sim642.adventofcodelib.IterableImplicits._
4
4
5
5
object Day1 {
6
6
7
- def totalListDistance (lists : Seq [( Int , Int )] ): Int = {
8
- val (list1, list2 ) = lists.unzip
9
- (list1 .sorted lazyZip list2 .sorted)
7
+ def totalListDistance (lists : ( Seq [Int ], Seq [ Int ]) ): Int = {
8
+ val (left, right ) = lists
9
+ (left .sorted lazyZip right .sorted)
10
10
.map((i, j) => (i - j).abs)
11
11
.sum
12
12
}
13
13
14
- def similarityScore (lists : Seq [( Int , Int )] ): Int = {
15
- val (list1, list2 ) = lists.unzip
16
- val list2Count = list2 .groupCount(identity).withDefaultValue(0 )
17
- list1
18
- .map(i => i * list2Count (i))
14
+ def similarityScore (lists : ( Seq [Int ], Seq [ Int ]) ): Int = {
15
+ val (left, right ) = lists
16
+ val rightCount = right .groupCount(identity).withDefaultValue(0 )
17
+ left
18
+ .map(i => i * rightCount (i))
19
19
.sum
20
20
}
21
21
22
22
def parsePair (s : String ): (Int , Int ) = s match {
23
23
case s " $i $j" => (i.toInt, j.toInt)
24
24
}
25
25
26
- def parseLists (input : String ): Seq [( Int , Int )] = input.linesIterator.map(parsePair).toSeq
26
+ def parseLists (input : String ): ( Seq [Int ], Seq [ Int ]) = input.linesIterator.map(parsePair).toSeq.unzip
27
27
28
28
lazy val input : String = scala.io.Source .fromInputStream(getClass.getResourceAsStream(" day1.txt" )).mkString.trim
29
29
0 commit comments