Skip to content

Commit 016b501

Browse files
author
Emre Akgül (CarTelSol)
committed
continue day 21
1 parent 77da111 commit 016b501

File tree

1 file changed

+7
-8
lines changed
  • src/main/kotlin/tr/emreone/adventofcode/days

1 file changed

+7
-8
lines changed

src/main/kotlin/tr/emreone/adventofcode/days/Day21.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package tr.emreone.adventofcode.days
22

33
import tr.emreone.kotlin_utils.automation.Day
44
import tr.emreone.kotlin_utils.extensions.area
5-
import tr.emreone.kotlin_utils.extensions.formatted
65
import tr.emreone.kotlin_utils.extensions.height
76
import tr.emreone.kotlin_utils.extensions.width
87
import tr.emreone.kotlin_utils.math.*
9-
import java.util.Queue
8+
import kotlin.math.max
109

1110
class Day21 : Day(21, 2023, "Step Counter") {
1211

@@ -133,12 +132,12 @@ class Day21 : Day(21, 2023, "Step Counter") {
133132
require(startingPoint.x == startingPoint.y)
134133
require(startingPoint.x == mapSize / 2)
135134

136-
val gridWidth = totalSteps / mapSize - 1
137-
val oddMaps = ((gridWidth / 2) * 2 + 1).pow(2)
138-
val evenMaps = ((gridWidth + 1) / 2 * 2).pow(2)
135+
val factor = max(0, totalSteps / mapSize - 1)
136+
val evenMaps = ((factor / 2) * 2 + 1).pow(2)
137+
val oddMaps = ((factor + 1) / 2 * 2).pow(2)
139138

140-
val oddPoints = this.fillGarden(startingPoint, mapSize * 2 + 1).size
141139
val evenPoints = this.fillGarden(startingPoint, mapSize * 2).size
140+
val oddPoints = this.fillGarden(startingPoint, mapSize * 2 + 1).size
142141

143142
val cornerTop = this.fillGarden(Point(startingPoint.x, mapSize - 1), mapSize - 1).size
144143
val cornerRight = this.fillGarden(Point(0, startingPoint.y), mapSize - 1).size
@@ -161,8 +160,8 @@ class Day21 : Day(21, 2023, "Step Counter") {
161160
oddMaps * oddPoints.toLong(),
162161
evenMaps * evenPoints.toLong(),
163162
cornerTop + cornerRight + cornerBottom + cornerLeft.toLong(),
164-
(gridWidth.toLong() + 1) * (smallTopRight + smallBottomRight + smallBottomLeft + smallTopLeft),
165-
gridWidth.toLong() * (bigTopRight + bigBottomRight + bigBottomLeft + bigTopLeft)
163+
(factor.toLong() + 1) * (smallTopRight + smallBottomRight + smallBottomLeft + smallTopLeft),
164+
factor.toLong() * (bigTopRight + bigBottomRight + bigBottomLeft + bigTopLeft)
166165
)
167166

168167
println("Total steps: $totalPoints")

0 commit comments

Comments
 (0)