Skip to content

Commit 4ebbddc

Browse files
committed
Solve part 1 day 9
1 parent ab0f7d4 commit 4ebbddc

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

src/Day9.kt

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,44 @@
11
private const val DAY = 9
22

33
fun main() {
4-
fun part1(input: List<String>) =-1
5-
fun part2(input: List<String>) = -1
4+
fun part1(input: List<List<Byte>>): Int {
5+
var sum = 0
6+
for (x in input.indices) {
7+
for (y in input[0].indices) {
8+
val currentHeight = input[x][y]
9+
if (x > 0 && currentHeight >= input[x-1][y]) {
10+
continue
11+
}
12+
if (y > 0 && currentHeight >= input[x][y-1]) {
13+
continue
14+
}
15+
if (x < input.size - 1 && currentHeight >= input[x+1][y]) {
16+
continue
17+
}
18+
if (y < input[0].size - 1 && currentHeight >= input[x][y+1]) {
19+
continue
20+
}
21+
sum += currentHeight + 1
22+
}
23+
}
24+
return sum
25+
}
26+
fun part2(input: List<List<Byte>>) = -1
627

728
// test if implementation meets criteria from the description, like:
8-
val testInput = readInput(day = DAY, useTestInput = true)
29+
val testInput = parseInput(readInput(day = DAY, useTestInput = true))
930
check(part1(testInput) == 15)
10-
check(part2(testInput) == 61229)
31+
// check(part2(testInput) == 61229)
1132

12-
val input = readInput(day = DAY)
33+
val input = parseInput(readInput(day = DAY))
1334
println(part1(input))
1435
println(part2(input))
36+
}
37+
38+
private fun parseInput(input: List<String>): List<List<Byte>> {
39+
return input.map {
40+
it.map {
41+
it.toString().toByte()
42+
}
43+
}
1544
}

0 commit comments

Comments
 (0)