Skip to content

Commit 04071ea

Browse files
committed
Day 5 - code cleanup
1 parent 4846d17 commit 04071ea

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

doc/day5.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ map over the range of changing values for one half of our pair, while the other
3030
```kotlin
3131
fun Line.isHorizontal() = this.first.first == this.second.first
3232
fun Line.isVertical() = this.first.second == this.second.second
33-
fun Line.getHorizontalPoints() = (this.first.second.progressionBetween(this.second.second)).map { y -> this.first.first to y }
34-
fun Line.getVerticalPoints() = (this.first.first.progressionBetween(this.second.first)).map { x -> x to this.first.second }
33+
fun Line.getHorizontalPoints() = (this.first.second.progressionTo(this.second.second)).map { y -> this.first.first to y }
34+
fun Line.getVerticalPoints() = (this.first.first.progressionTo(this.second.first)).map { x -> x to this.first.second }
3535
```
36-
Those that know Kotlin might be wondering what `progressionBetween()` is. Frustratingly, Kotlin only honors ranges/progressions
36+
Those that know Kotlin might be wondering what `progressionTo()` is. Frustratingly, Kotlin only honors ranges/progressions
3737
that are defined in the correct order, so I made this convenience method to sort it out.
3838
```kotlin
39-
fun Int.progressionBetween(i: Int): IntProgression =
39+
fun Int.progressionTo(i: Int): IntProgression =
4040
if(this > i) { i..this }
4141
else { i downTo this }
4242
```

src/main/kotlin/Day5.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ fun main() {
1010
typealias Point = Pair<Int, Int>
1111
typealias Line = Pair<Point, Point>
1212

13-
fun Int.progressionBetween(i: Int): IntProgression =
13+
fun Int.progressionTo(i: Int): IntProgression =
1414
if(this > i) { i..this }
1515
else { i downTo this }
1616

1717
fun Line.isHorizontal() = this.first.first == this.second.first
1818
fun Line.isVertical() = this.first.second == this.second.second
19-
fun Line.getHorizontalPoints() = (this.first.second.progressionBetween(this.second.second)).map { y -> this.first.first to y }
20-
fun Line.getVerticalPoints() = (this.first.first.progressionBetween(this.second.first)).map { x -> x to this.first.second }
19+
fun Line.getHorizontalPoints() = (this.first.second.progressionTo(this.second.second)).map { y -> this.first.first to y }
20+
fun Line.getVerticalPoints() = (this.first.first.progressionTo(this.second.first)).map { x -> x to this.first.second }
2121
fun Line.get45DegreePoints() = getVerticalPoints().map { it.first }.zip(getHorizontalPoints().map { it.second })
2222

2323
fun Line.getAllPoints(allow45degree: Boolean): List<Point> =

0 commit comments

Comments
 (0)