2
$\begingroup$

I would like to generate a random 100 x 100 Lattice, plot this and then, say, the first 3 iterations of Conway's Game of Life.

How can I do this with Mathematica?

I only came up with:

gameOfLife = {224, {2, {{2, 2, 2}, {2, 1, 2}, {2, 2, 2}}}, {1, 1}};
board = RandomInteger[1, {100, 100}];
ArrayPlot[board]
ArrayPlot[Last[ CellularAutomaton[gameOfLife, board, {{0, 1}}]] ]

Does this show the first iteration?

$\endgroup$
1
  • 1
    $\begingroup$ Why RandomInteger and not for instance ConstantArray? Speed-wise there's not much of a difference, and both generate packed arrays (contrary to Table which is 5 times faster), but I can imagine that 'random' may be confusing to the reader. $\endgroup$ Mar 25 '21 at 13:13
2
$\begingroup$

This shows the 10 first iteration for a simple starting configuration: board:

board = ConstantArray[0, {100, 100}]; board[[50 ;; 52, 50 ;; 53]] = 1;
ArrayPlot /@ CellularAutomaton["GameOfLife", board, 10]

enter image description here

$\endgroup$
7
  • $\begingroup$ I do njot understand what board = RandomInteger[0, {100, 100}]; board[[50 ;; 52, 50 ;; 53]] = 1; is doing. $\endgroup$
    – C.D.
    Mar 25 '21 at 13:27
  • $\begingroup$ It simply sets up a board 100x100 with all zeros (aka dead cells) and some pixels in the center (aka life cells) to one. $\endgroup$ Mar 25 '21 at 13:30
  • $\begingroup$ Sorry I was simply too lazy and took your code and changed it in the simplest way possible. I corrected the answer. $\endgroup$ Mar 25 '21 at 13:39
  • $\begingroup$ Now, I get what you did, thanks. But why not starting with a random table consisting of zeros and ones? I want to start with a random setup. $\endgroup$
    – C.D.
    Mar 25 '21 at 13:42
  • $\begingroup$ That's o.k., but I wanted to see the if the evolution works o.k. and that can be easier done with a simple pattern. $\endgroup$ Mar 25 '21 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.