File tree Expand file tree Collapse file tree 1 file changed +34
-5
lines changed
Expand file tree Collapse file tree 1 file changed +34
-5
lines changed Original file line number Diff line number Diff line change 11private const val DAY = 9
22
33fun 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}
You can’t perform that action at this time.
0 commit comments