Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from random import choice
- import sys
- from csplot import *
- sys.setrecursionlimit(100000)
- def main(): # Defines the main function that allows other coders to use the runGenerations function.
- results = runGenerations2d(randBL2d(6))
- print(results)
- def runGenerations2d(L):
- show(L)
- print(L)
- if allOnes2d(L) == True:
- return 0
- newL = evolve2d(L)
- return 1 + runGenerations2d(newL)
- def evolve2d(L):
- N = len(L)
- x, y = sqinput2()
- return [[setNewElement2d(L, i, j, x, y) for i in range(N)] for j in range(N)]
- def setNewElement2d(L, i, j, x=0, y=0):
- if i == x and j == y:
- print(x, y)
- return 1-L[i][j]
- elif i == x-1 and j == y-1:
- print(x, y)
- return 1-L[i][j]
- elif i == x+1 and j == y+1:
- print(x, y)
- return 1-L[i][j]
- else:
- return L[i][j]
- #return 1-L[i][j]
- def allOnes2d(L): #Not working, ignore this part for now, not essential.
- areTheseOnes = True
- for i in L:
- if i != 1:
- areTheseOnes = False
- for j in L:
- if j != 1:
- areTheseOnes = False
- return areTheseOnes
- def randBL2d(N):
- return [[choice([0, 1]) for i in range(N)] for j in range(N)]
- if __name__=='__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement