Решение на Игра на живот от Димитър Вачев

Обратно към всички решения

Към профила на Димитър Вачев

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)

Код

def step_board(board):
def living_force(board, row, col):
edge = [0, BOARD_SIZE + 1]
if row in edge or col in edge:
return 0
square = [_, __ for ]
neighbours = [board[_][__]
for _ in range(row - 1,row + 2)
for __ in range(col - 1, col + 2)]
res = sum(neighbours) - board[row][col]
return res
new_board = [[1 if (board[i][j] and living_force(board, i, j) in
[2,3]) or
not board[i][j] and living_force(board, i, j) == 3
else 0
for j in range(len(board[i]))]
for i in range(len(board))]
for row in range(len(board)):
board[row] = new_board[row][:]

Лог от изпълнението

Traceback (most recent call last):
  File "/tmp/test20120625-4142-y2ap28", line 43, in <module>
    GameOfLifeTestCase.main()
  File "/data/rails/pyfmi-2012/releases/20120501152555/python/homework.py", line 27, in main
    rude.solution = module or imp.load_source('solution', sys.argv[1])
  File "/tmp/solution20120625-4142-19ou1cm", line 7
    square = [_, __ for ]
                      ^
SyntaxError: invalid syntax

История (1 версия и 0 коментара)

Димитър обнови решението на 26.03.2012 16:56 (преди почти 13 години)

+def step_board(board):
+ def living_force(board, row, col):
+ edge = [0, BOARD_SIZE + 1]
+ if row in edge or col in edge:
+ return 0
+
+ square = [_, __ for ]
+ neighbours = [board[_][__]
+ for _ in range(row - 1,row + 2)
+ for __ in range(col - 1, col + 2)]
+ res = sum(neighbours) - board[row][col]
+
+ return res
+
+ new_board = [[1 if (board[i][j] and living_force(board, i, j) in
+[2,3]) or
+ not board[i][j] and living_force(board, i, j) == 3
+else 0
+ for j in range(len(board[i]))]
+ for i in range(len(board))]
+
+ for row in range(len(board)):
+ board[row] = new_board[row][:]