fork download
  1. s = 3 #int(input("size: "))
  2. field = [["0" for x in range(s)]for x in range(s)]
  3.  
  4. def prf(): #PRint Field
  5. print("\n")
  6. for x in field:
  7. print(" ".join(map(str, x)))
  8. print("\n")
  9.  
  10. prf()
  11.  
  12. def set(x,y,v): #set value by position
  13. global field
  14. field[y][x] = str(v)
  15.  
  16. def get(x,y): #get value by position
  17. return field[y][x]
  18.  
  19. """def ask2set():
  20. while True:
  21. inp = input()
  22. if inp == "p":
  23. break
  24. else:
  25. inp = list(map(int, inp.split()))
  26. set(inp[0],inp[1],inp[2])
  27. print("\n")
  28. prf()"""
  29.  
  30. def check(x,y):
  31. alive = []
  32. dead = []
  33. for i in [x-1, x, x+1]:
  34. for j in [y+1, y, y-1]:
  35. try:
  36. if int(get(i, j)) and (i,j) != (x,y):
  37. alive.append((i,j))
  38. elif (i,j) != (x,y):
  39. dead.append((i,j))
  40. except:
  41. return "0"
  42. if not int(get(x, y)) and len(alive) == 3:
  43. return "1"
  44. elif int(get(x, y)) and len(alive) > 1 and len(alive) < 4:
  45. return "1"
  46. elif int(get(x, y)) and (len(alive) < 1 or len(alive) > 4):
  47. return "0"
  48.  
  49. def play():
  50. for x in range(s):
  51. for y in range(s):
  52. set(x, y, check(x,y))
  53. prf()
  54.  
  55.  
  56. set(0, 0, 1)
  57. prf()
  58.  
  59. set(0, 1, 1)
  60. prf()
  61. set(1, 0, 1)
  62. prf()
  63. play()
  64. play()
  65. play()
Success #stdin #stdout 0.01s 9992KB
stdin
Standard input is empty
stdout

0 0 0
0 0 0
0 0 0




1 0 0
0 0 0
0 0 0




1 0 0
1 0 0
0 0 0




1 1 0
1 0 0
0 0 0




1 1 0
1 1 0
0 0 0




1 1 0
1 1 0
0 0 0




1 1 0
1 1 0
0 0 0