Skip to content

Commit

Permalink
Replace reduce(_ + _) with sum
Browse files Browse the repository at this point in the history
  • Loading branch information
flvrone committed Jan 16, 2025
1 parent e4d083c commit 32f9ff2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 11/long_plutonian_pebbles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def main2(inputFileName: String): Unit =
val nums = lines.apply(0).split("\\s+").map(_.toLong).toVector

val numCounts = compressAndBlink(nums, 75)
println(numCounts.values.reduce(_ + _))
println(numCounts.values.sum)

def compressAndBlink(nums: Vector[Long], iterations: Int = 1): Map[Long, Long] =
val numCounts =
Expand Down
8 changes: 4 additions & 4 deletions 12/discounted_fence.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def horizontalSidesCount(
.groupMap(_.row)(_.col)
.values
.map(separateProgressionsCount(_))
.reduce(_ + _)
).reduce(_ + _)
.sum
).sum

def verticalSidesCount(
map: Char2DMatrix, plot: List[Coord], identifier: Char
Expand All @@ -142,8 +142,8 @@ def verticalSidesCount(
.groupMap(_.col)(_.row)
.values
.map(separateProgressionsCount(_))
.reduce(_ + _)
).reduce(_ + _)
.sum
).sum

def coordBordersInDirection(
map: Char2DMatrix, coord: Coord, identifier: Char, dir: Direction
Expand Down
2 changes: 1 addition & 1 deletion 5/print_queue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main1(inputFileName: String): Unit =
println(
queues.filter(isQueueCorrect(_, rulesMap))
.map(middleElement(_))
.reduce(_ + _)
.sum
)

def buildRulesMap(rules: Seq[String]): Map[Int, Set[Int]] =
Expand Down
2 changes: 1 addition & 1 deletion 5/queue_order_fixer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main2(inputFileName: String): Unit =
queues.filter(isQueueIncorrect(_, rulesMap))
.map(_.sortWith(isOrderCorrectPredicate))
.map(middleElement(_))
.reduce(_ + _)
.sum
)

def buildRulesMap(rules: Seq[String]): Map[Int, Set[Int]] =
Expand Down

0 comments on commit 32f9ff2

Please sign in to comment.