Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import time
  2. from random import choice
  3. import sys
  4. from csplot import *
  5.  
  6. sys.setrecursionlimit(100000)
  7.  
  8. def main(): # Defines the main function that allows other coders to use the runGenerations function.
  9. results = runGenerations2d(randBL2d(6))
  10. print(results)
  11.  
  12. def runGenerations2d(L):
  13. show(L)
  14. print(L)
  15. if allOnes2d(L) == True:
  16. return 0
  17. newL = evolve2d(L)
  18. return 1 + runGenerations2d(newL)
  19.  
  20. def evolve2d(L):
  21. N = len(L)
  22. x, y = sqinput2()
  23. return [[setNewElement2d(L, i, j, x, y) for i in range(N)] for j in range(N)]
  24.  
  25. def setNewElement2d(L, i, j, x=0, y=0):
  26. if i == x and j == y:
  27. print(x, y)
  28. return 1-L[i][j]
  29. elif i == x-1 and j == y-1:
  30. print(x, y)
  31. return 1-L[i][j]
  32. elif i == x+1 and j == y+1:
  33. print(x, y)
  34. return 1-L[i][j]
  35. else:
  36. return L[i][j]
  37. #return 1-L[i][j]
  38. def allOnes2d(L): #Not working, ignore this part for now, not essential.
  39. areTheseOnes = True
  40. for i in L:
  41. if i != 1:
  42. areTheseOnes = False
  43. for j in L:
  44. if j != 1:
  45. areTheseOnes = False
  46. return areTheseOnes
  47.  
  48. def randBL2d(N):
  49. return [[choice([0, 1]) for i in range(N)] for j in range(N)]
  50.  
  51. if __name__=='__main__':
  52. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement