-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay3.kt
More file actions
27 lines (22 loc) · 710 Bytes
/
Day3.kt
File metadata and controls
27 lines (22 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package me.markrobbo
private class Map(val terrain: List<String>) {
fun numTreesOnSlope(right: Int, down: Int): Int {
return (down until terrain.size step down).count {
terrain[it][(right * (it / down)) % terrain[it].length] == '#'
}
}
}
class Day3 {
fun solvePart1(input: List<String>): Int {
val map = Map(input)
return map.numTreesOnSlope(3, 1)
}
fun solvePart2(input: List<String>): Long {
val map = Map(input)
return map.numTreesOnSlope(1, 1).toLong() *
map.numTreesOnSlope(3, 1) *
map.numTreesOnSlope(5, 1) *
map.numTreesOnSlope(7, 1) *
map.numTreesOnSlope(1, 2)
}
}