Move direction enum to own file.
This commit is contained in:
parent
267ffda2e9
commit
d9172dabbf
2 changed files with 21 additions and 22 deletions
21
2024/src/main/kotlin/Direction.kt
Normal file
21
2024/src/main/kotlin/Direction.kt
Normal 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)
|
||||||
|
}
|
|
@ -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")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue