Skip to content

Commit 1be85c9

Browse files
committed
Refactor
1 parent 7f2cab4 commit 1be85c9

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/Day11.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
private const val DAY = 11
22

33
fun main() {
4-
fun part1(input: Array<IntArray>): Int {
5-
val octopuses = input.map { it.clone() }.toTypedArray()
4+
fun part1(input: List<List<Int>>): Int {
5+
val octopuses = input.map { it.toIntArray() }.toTypedArray()
66
var flashCount = 0
77
repeat(100) {
88
// increase energy level of all by one
@@ -33,8 +33,8 @@ fun main() {
3333
return flashCount
3434
}
3535

36-
fun part2(input: Array<IntArray>): Int {
37-
val octopuses = input.map { it.clone() }.toTypedArray()
36+
fun part2(input: List<List<Int>>): Int {
37+
val octopuses = input.map { it.toIntArray() }.toTypedArray()
3838
var totalFlashCount = 0
3939
var step = 0
4040
while(true) {
@@ -64,12 +64,11 @@ fun main() {
6464
}
6565
}
6666
}
67-
if (flashCountInStep == 100) {
67+
if (flashCountInStep == 100) { // if all flashing synchronized
6868
return step
6969
}
7070
totalFlashCount += flashCountInStep
7171
}
72-
return -1
7372
}
7473

7574
// test if implementation meets criteria from the description, like:
@@ -152,6 +151,6 @@ private fun makeOctopusFlash(octopuses: Array<IntArray>, x: Int, y: Int, flashed
152151
}
153152
}
154153

155-
private fun List<String>.toIntArray(): Array<IntArray> {
156-
return map { it.toCharArray().map { it.toString().toInt() }.toIntArray() }.toTypedArray()
154+
private fun List<String>.toIntArray(): List<List<Int>> {
155+
return map { it.map { it.toString().toInt() } }
157156
}

0 commit comments

Comments
 (0)