1 """ Simulate octopus flashing """
8 def increment(octopodes, position):
9 for x in range(position[0] - 1, position[0] + 2):
10 if x < 0 or x > cols - 1:
13 for y in range(position[1] - 1, position[1] + 2):
14 if y < 0 or y > rows - 1:
21 def add_one(octopodes):
30 flashed_this_iter = True
31 while flashed_this_iter:
32 flashed_this_iter = False
35 if octopodes[y][x] > 9 and (x, y) not in flashed:
36 flashed_this_iter = True
37 flashed.append((x, y))
38 increment(octopodes, (x, y))
46 # if (x, y) in flashed:
47 # display_row.append("X")
49 # display_row.append(".")
50 # print("".join(display_row))
58 octopodes.append([random.randint(0, 9) for _ in range(cols)])
60 for gen in range(1, 100000000):
62 n_flashed = flash(octopodes)
64 print("###", gen, "###", n_flashed)
66 if n_flashed == (rows * cols):