From ba115a4c54f3610eeab5f00bcdda8390e000b6da Mon Sep 17 00:00:00 2001 From: Matthew Hill Date: Fri, 15 Nov 2024 12:08:12 -0700 Subject: [PATCH] Rename Direction.pair to Direction.toPair Rename the pair method to toPair to make it explicit what the type is being converted to, and to make it more in line with standard library functions, e.g. String::toInt --- .../com/geistindersh/aoc/helper/enums/Direction.kt | 2 +- .../com/geistindersh/aoc/helper/enums/Point2D.kt | 8 ++++---- .../kotlin/com/geistindersh/aoc/year2020/Day11.kt | 8 ++++---- .../kotlin/com/geistindersh/aoc/year2021/Day20.kt | 8 ++++---- .../kotlin/com/geistindersh/aoc/year2021/Day5.kt | 4 ++-- .../kotlin/com/geistindersh/aoc/year2022/Day23.kt | 12 ++++++------ .../com/geistindersh/aoc/year2023/day18/day18.kt | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/com/geistindersh/aoc/helper/enums/Direction.kt b/src/main/kotlin/com/geistindersh/aoc/helper/enums/Direction.kt index 0c58bfc..8824546 100644 --- a/src/main/kotlin/com/geistindersh/aoc/helper/enums/Direction.kt +++ b/src/main/kotlin/com/geistindersh/aoc/helper/enums/Direction.kt @@ -6,7 +6,7 @@ enum class Direction(val rowInc: Int, val colInc: Int) { East(0, 1), West(0, -1); - fun pair() = rowInc to colInc + fun toPair() = rowInc to colInc operator fun plus(pair: Pair) = Pair(pair.first + rowInc, pair.second + colInc) operator fun plus(direction: Direction) = Pair(rowInc + direction.rowInc, colInc + direction.colInc) diff --git a/src/main/kotlin/com/geistindersh/aoc/helper/enums/Point2D.kt b/src/main/kotlin/com/geistindersh/aoc/helper/enums/Point2D.kt index a9fa934..41146a0 100644 --- a/src/main/kotlin/com/geistindersh/aoc/helper/enums/Point2D.kt +++ b/src/main/kotlin/com/geistindersh/aoc/helper/enums/Point2D.kt @@ -7,10 +7,10 @@ data class Point2D(val row: Int, val col: Int) { fun neighbors() = listOf(Direction.North, Direction.East, Direction.South, Direction.West).map { this + it } fun neighborsAll() = listOf( - Direction.North.pair(), - Direction.East.pair(), - Direction.South.pair(), - Direction.West.pair(), + Direction.North.toPair(), + Direction.East.toPair(), + Direction.South.toPair(), + Direction.West.toPair(), Direction.North + Direction.East, Direction.North + Direction.West, Direction.South + Direction.East, diff --git a/src/main/kotlin/com/geistindersh/aoc/year2020/Day11.kt b/src/main/kotlin/com/geistindersh/aoc/year2020/Day11.kt index b566689..2f5f9ca 100644 --- a/src/main/kotlin/com/geistindersh/aoc/year2020/Day11.kt +++ b/src/main/kotlin/com/geistindersh/aoc/year2020/Day11.kt @@ -28,10 +28,10 @@ class Day11(dataFile: DataFile) { // Use the "raw" directions as opposed to Point::neighborsAll so we can repeatedly // add the current direction until we find a visible point val directions = listOf( - Direction.North.pair(), - Direction.East.pair(), - Direction.South.pair(), - Direction.West.pair(), + Direction.North.toPair(), + Direction.East.toPair(), + Direction.South.toPair(), + Direction.West.toPair(), Direction.North + Direction.East, Direction.North + Direction.West, Direction.South + Direction.East, diff --git a/src/main/kotlin/com/geistindersh/aoc/year2021/Day20.kt b/src/main/kotlin/com/geistindersh/aoc/year2021/Day20.kt index d06fb84..6683b5d 100644 --- a/src/main/kotlin/com/geistindersh/aoc/year2021/Day20.kt +++ b/src/main/kotlin/com/geistindersh/aoc/year2021/Day20.kt @@ -27,13 +27,13 @@ class Day20(dataFile: DataFile) { private fun orderedNeighbors() = listOf( Direction.North + Direction.West, - Direction.North.pair(), + Direction.North.toPair(), Direction.North + Direction.East, - Direction.West.pair(), + Direction.West.toPair(), Pair(0, 0), - Direction.East.pair(), + Direction.East.toPair(), Direction.South + Direction.West, - Direction.South.pair(), + Direction.South.toPair(), Direction.South + Direction.East, ) diff --git a/src/main/kotlin/com/geistindersh/aoc/year2021/Day5.kt b/src/main/kotlin/com/geistindersh/aoc/year2021/Day5.kt index d959f39..201ed20 100644 --- a/src/main/kotlin/com/geistindersh/aoc/year2021/Day5.kt +++ b/src/main/kotlin/com/geistindersh/aoc/year2021/Day5.kt @@ -26,8 +26,8 @@ class Day5(dataFile: DataFile) { val ewDirection = if (start.col < end.col) Direction.East else Direction.West val direction = when { - start.row == end.row -> ewDirection.pair() - start.col == end.col -> nsDirection.pair() + start.row == end.row -> ewDirection.toPair() + start.col == end.col -> nsDirection.toPair() else -> nsDirection + ewDirection } generateSequence(start) { it + direction } diff --git a/src/main/kotlin/com/geistindersh/aoc/year2022/Day23.kt b/src/main/kotlin/com/geistindersh/aoc/year2022/Day23.kt index 3bfa822..2048f06 100644 --- a/src/main/kotlin/com/geistindersh/aoc/year2022/Day23.kt +++ b/src/main/kotlin/com/geistindersh/aoc/year2022/Day23.kt @@ -19,27 +19,27 @@ class Day23(dataFile: DataFile) { private fun getAdjacency(direction: Direction) = when (direction) { Direction.North, Direction.South -> listOf( - direction.pair(), + direction.toPair(), direction + Direction.East, direction + Direction.West, ) Direction.East, Direction.West -> listOf( - direction.pair(), + direction.toPair(), direction + Direction.North, direction + Direction.South, ) } private fun getAllNeighbours() = listOf( - Direction.North.pair(), + Direction.North.toPair(), Direction.North + Direction.East, Direction.North + Direction.West, - Direction.South.pair(), + Direction.South.toPair(), Direction.South + Direction.East, Direction.South + Direction.West, - Direction.East.pair(), - Direction.West.pair(), + Direction.East.toPair(), + Direction.West.toPair(), ) private fun rounds() = sequence { diff --git a/src/main/kotlin/com/geistindersh/aoc/year2023/day18/day18.kt b/src/main/kotlin/com/geistindersh/aoc/year2023/day18/day18.kt index 6524c4a..db7b7bd 100644 --- a/src/main/kotlin/com/geistindersh/aoc/year2023/day18/day18.kt +++ b/src/main/kotlin/com/geistindersh/aoc/year2023/day18/day18.kt @@ -18,7 +18,7 @@ data class DigPlan(private val digLocations: List) { var area = 1.0 for (dig in digLocations) { // Offsets that will be used to generate the ending position of the range - val (row, col) = dig.direction.pair() + val (row, col) = dig.direction.toPair() // ending column position for the current location colPosition += col * dig.distance // The area added by the current location