def cellCompete(states, days): for day in range(days): newStates = states[:] for i in range(len(states)): if i == 0: if states[i+1] == 0: states[i] = 0 else: states[i] = 1 elif i == len(states) - 1: if states[i-1] == 0: states[i] = 0 else: states[i] = 1 else: if states[i-1] == states[i+1]: newStates[i] = 0 else: newStates[i] = 1 states = newStates[:] return states
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter