1
0
Fork 0

day(04): clean up and remove todo

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2021-12-05 11:23:15 +01:00
parent 2d4eb2b19e
commit f7ea52c685

View file

@ -20,22 +20,19 @@ class Bingo(description: List<String>) {
.toMutableList()
}
// TODO: Clean up
private fun mark(board: MutableList<MutableList<Int>>, number: Int) {
for (i in board.indices) {
for (j in board[i].indices) {
if (board[i][j] == number) {
val before = isWinningBoard(board)
board[i][j] = -1
val after = isWinningBoard(board)
board.indices
.flatMap { i -> board.indices.map { j -> Pair(i, j) } }
.filter { (i, j) -> board[i][j] == number }
.forEach { (i, j) ->
val before = isWinningBoard(board)
board[i][j] = -1
val after = isWinningBoard(board)
if (before != after) {
orderOfWin.add(board)
}
if (before != after) {
orderOfWin.add(board)
}
}
}
}
private fun isWinningBoard(board: MutableList<MutableList<Int>>): Boolean = board.indices.any { i ->
@ -59,6 +56,7 @@ class Bingo(description: List<String>) {
check(nextDraw > 0)
return draws[nextDraw - 1]
}
fun sumOfLast(): Int = orderOfWin.last().sumOf { row -> row.filter { it != -1 }.sum() }
}