Move direction enum to own file.

This commit is contained in:
Sven Weidauer 2024-12-11 20:43:01 +01:00
parent 267ffda2e9
commit d9172dabbf
2 changed files with 21 additions and 22 deletions

View file

@ -0,0 +1,21 @@
enum class Direction {
North,
East,
South,
West;
fun turnClockwise() = when(this) {
North -> East
East -> South
South -> West
West -> North
}
}
fun Grid.Coordinate.step(direction: Direction) =
when (direction) {
Direction.North -> copy(y = y - 1)
Direction.East -> copy(x = x + 1)
Direction.South -> copy(y = y + 1)
Direction.West -> copy(x = x - 1)
}

View file

@ -1,25 +1,3 @@
enum class Direction {
North,
East,
South,
West;
fun turnClockwise() = when(this) {
North -> East
East -> South
South -> West
West -> North
}
}
fun Grid.Coordinate.step(direction: Direction) =
when (direction) {
Direction.North -> copy(y = y - 1)
Direction.East -> copy(x = x + 1)
Direction.South -> copy(y = y + 1)
Direction.West -> copy(x = x - 1)
}
fun main() { fun main() {
val grid = CharGrid.read("day6.txt") val grid = CharGrid.read("day6.txt")