This commit is contained in:
2021-12-12 09:26:08 +01:00
parent 6ffaa01033
commit 5052110cb1
6 changed files with 172 additions and 5 deletions

View File

@ -49,14 +49,14 @@ class Day11: Runnable {
.map { Array($0) }
.map { ar in ar.map {c in Int(c.description)!} }
for _ in 0..<100 {
var step = 0
while(flashed.count < numRows * numCols) {
flashed = Set<Coord>()
for row in octopuses.indices {
for col in octopuses[row].indices {
octopuses[row][col] += 1
}
}
for row in octopuses.indices {
for col in octopuses[row].indices {
let coord = Coord(row: row, col: col)
@ -66,8 +66,12 @@ class Day11: Runnable {
for flash in flashed {
octopuses[flash] = 0
}
step += 1
if step == 100 {
print(numFlashes)
}
}
print(numFlashes)
print("All flashing at step: \(step)")
}
func checkAndFlash(at coord: Coord) {