Skip to content

Commit

Permalink
Replace reduceRight(_ + _) with sum
Browse files Browse the repository at this point in the history
  • Loading branch information
flvrone committed Jan 16, 2025
1 parent 32f9ff2 commit 1dde031
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 1/distance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def totalDistance(l1: List[Int], l2: List[Int]): Int =
val s1 = l1.sorted
val s2 = l2.sorted

s1.zip(s2).map((a, b) => (a - b).abs).reduceRight(_ + _)
s1.zip(s2).map((a, b) => (a - b).abs).sum
2 changes: 1 addition & 1 deletion 10/distinct_hiking_trails.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def trailheadsTotalScore(map: Height2DMap): Int =
yield
findHeightCoords(map, Coord(row, col)).length

scores.reduceRight(_ + _)
scores.sum

def findHeightCoords(
map: Height2DMap, startCoord: Coord, searchHeight: Int = 9
Expand Down
2 changes: 1 addition & 1 deletion 10/hiking_trails.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def trailheadsTotalScore(map: Height2DMap): Int =
yield
findHeightCoords(Visitable2DMap(map), Coord(row, col)).length

scores.reduceRight(_ + _)
scores.sum

def findHeightCoords(
map: Visitable2DMap, startCoord: Coord, searchHeight: Int = 9
Expand Down
2 changes: 1 addition & 1 deletion 12/discounted_fence.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def main2(inputFileName: String): Unit =

val map = Char2DMatrix(lines.toVector)

println(formPlots(map).map(plotFencePrice(map, _)).reduceRight(_ + _))
println(formPlots(map).map(plotFencePrice(map, _)).sum)

case class Coord(row: Int, col: Int)

Expand Down
4 changes: 2 additions & 2 deletions 12/garden_groups.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def main2(inputFileName: String): Unit =

val map = Char2DMatrix(lines.toVector)

println(formPlots(map).map(plotFencePrice(map, _)).reduceRight(_ + _))
println(formPlots(map).map(plotFencePrice(map, _)).sum)

case class Coord(row: Int, col: Int)

Expand Down Expand Up @@ -122,4 +122,4 @@ def plotPerimeter(map: Char2DMatrix, plot: List[Coord]): Int =
case Some(outerIdentifier) => outerIdentifier != identifier
case None => true
)
).reduceRight(_ + _)
).sum

0 comments on commit 1dde031

Please sign in to comment.