![]() ![]() Only when that is true, process that neighbor. You can fix these issues by filtering first the valid row coordinates, and for each of those, the valid column coordinates. When r is 4 (the last row), then the access to will trigger an exception, and the way this exception is handled means that born_count will remain zero, so ignoring the fact there are some other neighbors that should have been counted. A cell in the first row does not have neighbors in the 5 th row, so this is wrong. When r is 0, the access to will be to the last row. The second function checks the neighbour of each cell, counts alive neighbours and creates new multiline string, which represents the "board" state after one dead-alive check (or rather it was supposed to do so). The first function changes the multiline string input into a list with rows as its elements. Neighbours = ,game_list,game_list,game_list,game_list,game_list,game_list,game_list] Result = '' #life after day 1 (after one neighbour check for all cells) #if cell has 0-1 or 3+ alive neighbours(X) - dies X''')): #convert input into a list, so it is easier to operate on They represent a 5 by 7 fragment of the game field. # Input data will contain 5 lines of 7 characters each. # fill all marked empty cells with new organisms. ![]() Here is my code: #mark all places where new life will be born I don't understand why this code is not giving the correct answer. I need to calculate the next generation of this grid, which should be: -īut my code produces this output:. Given is a grid of 5 rows and 7 columns ("X" is alive, "-" is dead):.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |