Skip to content

Commit

Permalink
extracting Direction
Browse files Browse the repository at this point in the history
  • Loading branch information
kgeri committed Dec 22, 2022
1 parent 01af59f commit d3e44d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/main/kotlin/me/gergo/Aoc09.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ fun main() {
println("Positions visited by tail: ${ropeField.positionsVisitedByTail().count()}")
}

private enum class Direction { L, R, U, D }
private data class RopeStep(val dir: Direction, val steps: Int)
private data class Position(val x: Int, val y: Int) {
fun distanceFrom(o: Position) = max(abs(x - o.x), abs(y - o.y))
Expand Down
18 changes: 17 additions & 1 deletion src/main/kotlin/me/gergo/coordinates.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
package me.gergo

import kotlin.math.abs
enum class Direction {
L, U, R, D;

fun clockWise() = when (this) {
L -> U
U -> R
R -> D
D -> L
}

fun counterClockWise() = when (this) {
L -> D
U -> L
R -> U
D -> R
}
}

data class Coordinate(val x: Int, val y: Int)

Expand Down

0 comments on commit d3e44d7

Please sign in to comment.