day(04): clean up and remove todo
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
2d4eb2b19e
commit
f7ea52c685
1 changed files with 10 additions and 12 deletions
|
@ -20,12 +20,11 @@ class Bingo(description: List<String>) {
|
||||||
.toMutableList()
|
.toMutableList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: Clean up
|
|
||||||
private fun mark(board: MutableList<MutableList<Int>>, number: Int) {
|
private fun mark(board: MutableList<MutableList<Int>>, number: Int) {
|
||||||
for (i in board.indices) {
|
board.indices
|
||||||
for (j in board[i].indices) {
|
.flatMap { i -> board.indices.map { j -> Pair(i, j) } }
|
||||||
if (board[i][j] == number) {
|
.filter { (i, j) -> board[i][j] == number }
|
||||||
|
.forEach { (i, j) ->
|
||||||
val before = isWinningBoard(board)
|
val before = isWinningBoard(board)
|
||||||
board[i][j] = -1
|
board[i][j] = -1
|
||||||
val after = isWinningBoard(board)
|
val after = isWinningBoard(board)
|
||||||
|
@ -35,8 +34,6 @@ class Bingo(description: List<String>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isWinningBoard(board: MutableList<MutableList<Int>>): Boolean = board.indices.any { i ->
|
private fun isWinningBoard(board: MutableList<MutableList<Int>>): Boolean = board.indices.any { i ->
|
||||||
board[i].count { it == -1 } == board.size || board.indices.count { board[it][i] == -1 } == board.size
|
board[i].count { it == -1 } == board.size || board.indices.count { board[it][i] == -1 } == board.size
|
||||||
|
@ -59,6 +56,7 @@ class Bingo(description: List<String>) {
|
||||||
check(nextDraw > 0)
|
check(nextDraw > 0)
|
||||||
return draws[nextDraw - 1]
|
return draws[nextDraw - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sumOfLast(): Int = orderOfWin.last().sumOf { row -> row.filter { it != -1 }.sum() }
|
fun sumOfLast(): Int = orderOfWin.last().sumOf { row -> row.filter { it != -1 }.sum() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue