Skip to content

Commit

Permalink
Fixes & refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jurisk committed Dec 14, 2023
1 parent 2802a5d commit 09fff00
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion scala2/src/main/scala/jurisk/adventofcode/Advent00.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.scalatest.matchers.should.Matchers._
object Advent00 {
type Input = List[Command]

sealed trait Command
sealed trait Command extends Product with Serializable
object Command {
case object Noop extends Command
final case class Something(
Expand Down
31 changes: 14 additions & 17 deletions scala2/src/main/scala/jurisk/adventofcode/y2023/Advent14.scala
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
package jurisk.adventofcode.y2023

import cats.implicits._
import jurisk.adventofcode.y2023.Advent14.Square.{Cube, Empty, Round}
import jurisk.collections.BiMap
import jurisk.collections.BiMap.BiDirectionalArrowAssociation
import jurisk.geometry.{Field2D, Rotation}
import jurisk.utils.FileInput._
import jurisk.utils.Simulation

object Advent14 {
type Input = Field2D[Square]

sealed trait Square
sealed trait Square extends Product with Serializable
object Square {
case object Round extends Square
case object Cube extends Square
case object Empty extends Square

def parse(ch: Char): Square =
Map('O' -> Round, '#' -> Cube, '.' -> Empty).apply(ch)
val Mapping: BiMap[Char, Square] = BiMap(
'O' <-> Round,
'#' <-> Cube,
'.' <-> Empty,
)
}

def parse(input: String): Input =
Field2D.parse(input, Square.parse)
Field2D.parse(input, Square.Mapping.leftToRightUnsafe)

def debugPrint(input: Input): Unit =
Field2D.printField[Square](
input,
{
case Round => 'O'
case Cube => '#'
case Empty => '.'
},
)
Field2D.printField[Square](input, Square.Mapping.rightToLeftUnsafe)

private def slideRowLeft(row: Vector[Square]): Vector[Square] = {
import Vector.fill
Expand Down Expand Up @@ -60,16 +57,16 @@ object Advent14 {
slided.rotate(rotation.inverse)
}

def slideWest(data: Input): Input =
private[y2023] def slideWest(data: Input): Input =
slideHelper(data, Rotation.NoRotation)

def slideSouth(data: Input): Input =
private[y2023] def slideSouth(data: Input): Input =
slideHelper(data, Rotation.Right90)

def slideEast(data: Input): Input =
private[y2023] def slideEast(data: Input): Input =
slideHelper(data, Rotation.TurnAround)

def slideNorth(data: Input): Input =
private[y2023] def slideNorth(data: Input): Input =
slideHelper(data, Rotation.Left90)

def cycle(data: Input): Input =
Expand Down

0 comments on commit 09fff00

Please sign in to comment.