From d9172dabbfc7f4ff8d6c2b69bdfb984220bf12c8 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Wed, 11 Dec 2024 20:43:01 +0100 Subject: [PATCH] Move direction enum to own file. --- 2024/src/main/kotlin/Direction.kt | 21 +++++++++++++++++++++ 2024/src/main/kotlin/day6.kt | 22 ---------------------- 2 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 2024/src/main/kotlin/Direction.kt diff --git a/2024/src/main/kotlin/Direction.kt b/2024/src/main/kotlin/Direction.kt new file mode 100644 index 0000000..bc30103 --- /dev/null +++ b/2024/src/main/kotlin/Direction.kt @@ -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) + } \ No newline at end of file diff --git a/2024/src/main/kotlin/day6.kt b/2024/src/main/kotlin/day6.kt index 6d10fae..1b29c1a 100644 --- a/2024/src/main/kotlin/day6.kt +++ b/2024/src/main/kotlin/day6.kt @@ -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() { val grid = CharGrid.read("day6.txt")