Skip to content

Commit

Permalink
Do not use case class for classes with mutable Arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
flvrone committed Jan 16, 2025
1 parent faa2939 commit e4d083c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 10/hiking_trails.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ case class Height2DMap(rows: Vector[Vector[Int]]):

case class MapTile(height: Int, visited: Boolean = false)

case class Visitable2DMap(heightMap: Height2DMap):
class Visitable2DMap(heightMap: Height2DMap):
val visitableRows = heightMap.rows.map(row => row.map(MapTile(_)).toArray)

def tileAt(row: Int, col: Int): Option[MapTile] =
Expand Down
2 changes: 1 addition & 1 deletion 12/discounted_fence.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ case class Char2DMatrix(lines: Vector[String]):

case class MapTile(identifier: Char, visited: Boolean = false)

case class Visitable2DMap(map: Char2DMatrix):
class Visitable2DMap(map: Char2DMatrix):
val visitableRows = map.lines.map(line => line.map(MapTile(_)).toArray)

def tileAt(row: Int, col: Int): Option[MapTile] =
Expand Down
2 changes: 1 addition & 1 deletion 12/garden_groups.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ case class Char2DMatrix(lines: Vector[String]):

case class MapTile(identifier: Char, visited: Boolean = false)

case class Visitable2DMap(map: Char2DMatrix):
class Visitable2DMap(map: Char2DMatrix):
val visitableRows = map.lines.map(line => line.map(MapTile(_)).toArray)

def tileAt(row: Int, col: Int): Option[MapTile] =
Expand Down
2 changes: 1 addition & 1 deletion 6/patrol_loops.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ case class Tile2DMap(rows: Vector[Vector[MapTile]]):
def tileAt(coord: Coord): Option[MapTile] =
tileAt(coord.row, coord.col)

case class Visitable2DMap(tileMap: Tile2DMap):
class Visitable2DMap(tileMap: Tile2DMap):
val visitableRows = tileMap.rows.map(_.toArray)

def tileAt(row: Int, col: Int): Option[MapTile] =
Expand Down
6 changes: 4 additions & 2 deletions 6/patrol_map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def main1(inputFileName: String): Unit =
traverseMapFromPosition(map, position)

val visitedCount =
map.rows.map(_.count(_ == MapTile.VisitedPath)).reduce(_ + _)
map.rows
.map(row => row.count(_ == MapTile.VisitedPath))
.sum

println(visitedCount)

Expand All @@ -27,7 +29,7 @@ case class Position(coord: Coord, dir: Direction)
enum MapTile:
case Obstacle, Path, VisitedPath

case class Visitable2DMap(rows: Vector[Array[MapTile]]):
class Visitable2DMap(val rows: Vector[Array[MapTile]]):
def rowAt(idx: Int): Option[Array[MapTile]] =
if idx >= 0 && idx < rows.length then
Some(rows.apply(idx))
Expand Down

0 comments on commit e4d083c

Please sign in to comment.