(cells: list[list[int]], rule: list[int], time: int)
| 28 | |
| 29 | |
| 30 | def new_generation(cells: list[list[int]], rule: list[int], time: int) -> list[int]: |
| 31 | population = len(cells[0]) # 31 |
| 32 | next_generation = [] |
| 33 | for i in range(population): |
| 34 | # Get the neighbors of each cell |
| 35 | # Handle neighbours outside bounds by using 0 as their value |
| 36 | left_neighbor = 0 if i == 0 else cells[time][i - 1] |
| 37 | right_neighbor = 0 if i == population - 1 else cells[time][i + 1] |
| 38 | # Define a new cell and add it to the new generation |
| 39 | situation = 7 - int(f"{left_neighbor}{cells[time][i]}{right_neighbor}", 2) |
| 40 | next_generation.append(rule[situation]) |
| 41 | return next_generation |
| 42 | |
| 43 | |
| 44 | def generate_image(cells: list[list[int]]) -> Image.Image: |
no test coverage detected