# we need some container storing dead and alive cells # '#' for a living cell, ' ' for a dead cell width = 600 current_population = list(' ' for _ in range(width)) current_population[300] = '#' # we need something to represent a cell state # 0 for a dead cell, and 1 for a living cell # False for a dead cell, and True for a living cell # ' ' / space for a dead cell, and '#' for a living # we need some window sliding function which will give us the cell state of 3 # cells def window(population, index): return population[index-1:index+2] # we need some function which will calculate the new population based on the # current population # iterate function, create_new_population, time_step def create_new_population(population, rules): new_population = list(population) # change the new_population for index in range(1, len(population)-1): pattern = "".join(window(population, index)) new_population[index] = rules[pattern] return new_population # we need some way to represent the rules rule_30 = { '###': ' ', '## ': ' ', '# #': ' ', '# ': '#', ' ##': '#', ' # ': '#', ' #': '#', ' ': ' ', } rule_110 = { '###': ' ', '## ': '#', '# #': '#', '# ': ' ', ' ##': '#', ' # ': '#', ' #': '#', ' ': ' ', } # we need something that will output our population import time while True: output_str = "".join(current_population) # print the current population print(output_str) # create a new population current_population = create_new_population(current_population, rule_30) # step control input() # we need some kind of flow control (maybe?)