Clean a bit + tests
This commit is contained in:
@@ -18,13 +18,11 @@ class Day03(@Lines val input: Input<List<String>>) {
|
||||
|
||||
val width = grid.first().length
|
||||
|
||||
while (true) {
|
||||
while (y < grid.size - 1) {
|
||||
x += slope.x
|
||||
y += slope.y
|
||||
|
||||
if (x >= width) x -= width
|
||||
if (y >= grid.size) break
|
||||
if (grid[y][x] == '#') trees++
|
||||
if (grid[y][x % width] == '#') trees++
|
||||
}
|
||||
|
||||
return trees
|
||||
@@ -37,15 +35,11 @@ class Day03(@Lines val input: Input<List<String>>) {
|
||||
Slope(x = 7, y = 1),
|
||||
Slope(x = 1, y = 2),
|
||||
)
|
||||
.map { it to part1(it) }
|
||||
.onEach { println("$it") }
|
||||
.map { it.second.toLong() }
|
||||
.map { part1(it).toLong() }
|
||||
.reduce { acc, trees -> acc * trees }
|
||||
}
|
||||
|
||||
fun main() {
|
||||
with(createDay<Day03>()) {
|
||||
println(part1().also { check(it == 294) })
|
||||
println(part2().also { check(it == 5774564250) })
|
||||
}
|
||||
fun main() = with(createDay<Day03>()) {
|
||||
println(part1())
|
||||
println(part2())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user