@@ -4,26 +4,26 @@ import eu.sim642.adventofcodelib.IterableImplicits._
44
55object Day1 {
66
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)
1010 .map((i, j) => (i - j).abs)
1111 .sum
1212 }
1313
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))
1919 .sum
2020 }
2121
2222 def parsePair (s : String ): (Int , Int ) = s match {
2323 case s " $i $j" => (i.toInt, j.toInt)
2424 }
2525
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
2727
2828 lazy val input : String = scala.io.Source .fromInputStream(getClass.getResourceAsStream(" day1.txt" )).mkString.trim
2929
0 commit comments