Given a matrix A that represents the state of Conway's game of Life at one instant (time t=n), return the matrix B that represents the state of the game at the next instant (time t=n+1).
Assume a toroidal game board, so the edges of the matrix wrap left to right and top to bottom.
Examples:
Input A = [ 1 1 0 0 0 1 0 0 1 1 0 0 0 0 0 0 ]
Output B = [ 1 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 ]
Input A = [ 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 ]
Output B = [ 1 0 1 1 1 0 0 0 0 0 1 1 0 1 1 0 ]
I think test sets should be designed to encourage general solutions. At present, the test set only has square boards - some more varied examples would make solvers seek code that is general.
Is there something wrong with the test suite? function B = life(A) B = A; end produces "Error using life Too many output arguments." See comment on solution 1019804.
I suppose the error "Error using life Too many output arguments." is due to shadowing. It seems thet test suite calls \toolbox\matlab\demos\life.m
I had so much fun with this problem. Thank you.
Is there a syntax flaw in the Test Suite? Currently the first test displays with a first line of "%%A = [ ...", and in my solution (S 1435695) only the second test is displayed. Although apparently the first test is still being called (S 1435709)?
Is there something wrong with the test suite?
function B = life(A)
B = A;
end
produces "Error using life Too many output arguments."
This solution is for only a 4x4 A. See Solution 598430 for general solution.
This is the solution for A of any size.
Ties the current leader in size, but works on all board sizes.
This stops working if the input is not 4x4.
Nice way of expanding A for circular convolution
Humph! Solution 2234 uses imfilter, but this fails with imfilter not found!
Nice - but only works for 4x4 boards.
Puzzling - solution 2231 uses imfilter but this solution fails because padarray isn't available. Both are in the IPT.
Nice usage of a simpler matrix for convolution (ones(3)) and readjustment of the logical conditions.
Good job!
I was looking for a command to do a circular convolution, but couldn't figure it out. This is useful to learn and, I guess, the whole point of Cody
However, learning is severely hindered by not being able to view solutions of smaller size. At least, as far as i know, this is not possible.
_All_ solutions in this Problem will become viewable after you solve _another_ Problem in the same category (which here is "Cody Challenge").
Find the numeric mean of the prime numbers in a matrix.
5610 Solvers
Back to basics 18 - justification
145 Solvers
168 Solvers
353 Solvers
465 Solvers