Kill Time At Work With Recreational Math: Conway's Game of Life by procrastilearner

View this thread on steempeak.com
· @procrastilearner · (edited)
$17.21
Kill Time At Work With Recreational Math: Conway's Game of Life
<div class="pull-right">https://steemitimages.com/DQmXpRewiotCbKDMn69XhZY5qcXkuNb3pXn4k2jncSXedBy/image.png</div>

This is the sixth in my series of killing time at work using math (here are the others [1](https://steemit.com/math/@procrastilearner/kill-time-at-work-with-recreational-math-testing-the-excel-random-function), [2](https://steemit.com/math/@procrastilearner/kill-time-at-work-with-recreational-math-testing-the-excel-random-function), [3](https://steemit.com/steemstem/@procrastilearner/kill-time-at-work-with-recreational-math-strange-attractors), [4](https://steemit.com/steemstem/@procrastilearner/kill-time-at-work-with-recreational-math-let-s-travel-to-alpha-centauri) and [5](https://steemit.com/steemstem/@procrastilearner/kill-time-at-work-with-recreational-math-calculate-sunset-and-sunrise-times)).

If you have read my posts before you already know that there are a few prerequisites for this:

* You like recreational math.
* You work at a computer and have access to Microsoft Excel.
* You are bored out of your tree.
* You don't want to get caught slacking off.

Let's get started.

---

Conway's game of life is an example of a simple [cellular automaton](https://en.wikipedia.org/wiki/Cellular_automaton) created by [John Conway](https://en.wikipedia.org/wiki/Conway's_Game_of_Life) in 1970.

The rules are, as I said, quite simple. Set up a rectangular grid, these will be the 'cells'.

Set some of those cells to 'alive' (=".") and some of the cells to 'dead' (=""). This will be the first generation.

The next generation will depend on the state of the grid in the first generation. To do this look at each cell one by one and apply the following rules:

*  A living cell that has fewer than 2 living neighbours will die (as if caused by under-population).
* A living cell with 2 or 3 living neighbours will live on to the next generation (this would simulate an optimal population density).
* A living cell with more than 3 living neighbours will die (as if caused by overpopulation and famine).
* If a cell is dead (empty) and has exactly 3 living neighbours it will become a living cell (as if by reproduction).
* Repeat the whole process all over again to create the 3<sup>rd</sup> generation, etc, etc.

From these simple rules amazingly complex patterns emerge.

## Excel Calculation Options

![](https://steemitimages.com/DQmPQxMaujJMy8eA8HJjLATW1geUGGvGyAski8CsvZjZBWd/image.png)

1. Go to the File tab in Excel and choose Options.
2. When the Options dialogue pops up choose Formulas. 
3. The Dialogue for formula/calcuation options will appear. 
4. In this dialogue make sure you set the maximum number of iterations for calculations to 1 (circled in red). If you don't Excel will simply scream through all of the calculations and you will not see anything except for the final generation.

## The Spreadsheet

We want to get this task done without having to resort to VBA programming in Excel. That means doing it solely using the spreadsheet functions. Since Excel doesn't have loops we will therefore need to use multiple grids as shown below.

These are the Initializer Grid, Grid 1 and Grid 2. Grid 2 has to be below Grid 1 because of the order in which Excel checks and updates cells (it scans from left to right and top to bottom).

![](https://steemitimages.com/DQmewxNcjGUzctsxEKAKyMcWZVPCePuHcAwWDofFYNAK41c/image.png)

Set up a spreadsheet with 3 grid that are 12 x 12. The borders of each grid will be set to a colour of your choice and will remain empty.

---

<b>Cell C2:</b> This is the Reset Cell. Set this cell to equal 1 to get everything initialized. When set to 1 it tells grid 1 to clear everything and set the cells to whatever is in the Initializer Grid.

Once that is done then delete the value in the cell or set it to 0. Grids 1 and 2 will automatically update once this is done (you will have to hit F9 to get each iteration to update).

---

<b>Cell O2:</b> This toggles between the values 1 and 2. It tells Grid 1 and Grid 2 which one will be the active grid.

Cell equation:
=IF(C2=1,1,MOD(O2,2)+1)

---

## Initialization Grid

<b>Cells C6 to L15:</b> This is the initialization grid.
* The living cells are set to the period character:  .
* The dead cells are set to double quotes: ""
* Set up the cells in any way you like. For my example above I created a simple glider pattern.

---

## Grid 1
<b>Cells P6 to Y15:</b> This is Grid 1.

The equation is complex. I will show it first and then explain it near the bottom of this post.

Cell P6 equation:

=IF($C$2=1,C6,
IF($O$2=2,
P6,
IF(P20="",
IF(COUNTIF(O19:Q19,".")+COUNTIF(Q20,".")+COUNTIF(O21:Q21,".")+COUNTIF(O20,".")=3,".",""),
CHOOSE(COUNTIF(O19:Q19,".")+COUNTIF(Q20,".")+COUNTIF(O21:Q21,".")+COUNTIF(O20,".")+1,"","",".",".","","","","","",))))

Just copy and paste the above equation into the other 99 cells. Excel will auto-update the relative references for you.

---

## Grid 2
<b>Cells P20 to Y29:</b> This is Grid 2.

This equation is also complex. I will show it first and then explain it near the bottom of this post.

Cell P20 equation:

=IF($C$2=1,"",
IF($O$2=1,P20,
IF(P6="",
     IF(COUNTIF(O5:Q5,".")+COUNTIF(Q6,".")+COUNTIF(O7:Q7,".")+COUNTIF(O6,".")=3,".",""),
     CHOOSE(COUNTIF(O5:Q5,".")+COUNTIF(Q6,".")+COUNTIF(O7:Q7,".")+COUNTIF(O6,".")+1,"","",".",".","","","","","",))))

Just copy and paste the above equation into the other 99 cells. Excel will auto-update the relative references for you.

## The Results
First, I set the reset cell C2 to 1. Then I hit F9 to get the grids to reset.
Then I clear the reset cell and hit F9 again, and again, and again. The glider pattern moved along in the grid just as expected. Nice.

Here are the first 5 iterations. It keeps going until it hits the grid wall and then dies off.

<center>
Iteration 1
https://steemitimages.com/DQmdu7a6eJhEffVVxsjYoac5LvFTeRQiePKKZe4tNv5LR6Z/image.png
<br>Iteration 2
https://steemitimages.com/DQmUpkivVxgrjiNzM6RPwgHa2sQRAF7RBkC3uWsfVgDnGgq/image.png
<br>Iteration 3
https://steemitimages.com/DQmfUwgGeWkFiW3jT7wBfrzdHJ3rNgWv1jKtTPf6kQePJ6W/image.png
<br>Iteration 4
https://steemitimages.com/DQmNcwSUR7cusvkyxHJccqyWpGkEq2ULLrSTWUbUvHkpk1f/image.png
<br>Iteration 5
https://steemitimages.com/DQmapsyZy7MPUGb8dmjGurbJynKHKCAo4fYq4FWLuwznTha/image.png
</center>

## The Gory Details
If you want to simply copy the above equations into your spreadsheet then feel free to skip this section. Otherwise read on.

Remember Grid 2 mirrors Grid 1 in one iteration, then the toggle cell $O$2 toggles and the roles reverse (Grid 1 mirrors Grid 2). This is how you get around not having a loop function in Excel.

#### Grid 1 Equation Explained
Once again here is Cell P6 equation from Grid 1:
=IF($C$2=1,C6,
IF($O$2=2,
P6,
IF(P20="",
IF(COUNTIF(O19:Q19,".")+COUNTIF(Q20,".")+COUNTIF(O21:Q21,".")+COUNTIF(O20,".")=3,".",""),
CHOOSE(COUNTIF(O19:Q19,".")+COUNTIF(Q20,".")+COUNTIF(O21:Q21,".")+COUNTIF(O20,".")+1,"","",".",".","","","","","",))))

---

=IF($C$2=1,C6,
This part simply checks if the rest switch is set to 1. If true then the cell is set to the corresponding value in the initializer grid.

---

IF($O$2=2,
P6,
This is checks the toggle in $O$2. If it is 2 then the cell remains unchanged and is set to it current value (P6).

---

IF(P20="",
IF(COUNTIF(O19:Q19,".")+COUNTIF(Q20,".")+COUNTIF(O21:Q21,".")+COUNTIF(O20,".")=3,".",""),
This part checks if the cell in the Grid 2 (the mirror grid) is 'dead'. If it is dead then it uses the COUNTIF function to add up all of the living cells in mirror locations in Grid 2 (those with period symbols in them). If the count adds up to 3 the cell becomes alive.

---

CHOOSE(COUNTIF(O19:Q19,".")+COUNTIF(Q20,".")+COUNTIF(O21:Q21,".")+COUNTIF(O20,".")+1,"","",".",".","","","","","",))))
This part activates if the cell is 'alive'. It also uses the same COUNTIF equation to count up the number of living cells in the mirror locations in Grid 2. It then uses the CHOOSE function to choose a final value among all the several Conway rules. 

---
#### Grid 2 Equation Explained
Once again here is Cell P20 equation from Grid 2. Remember Grid 2 mirrors Grid 1 and vice-versa as the toggle cell ($O$2) toggles between 1 and 2:

=IF($C$2=1,"",
IF($O$2=1,P20,
IF(P6="",
     IF(COUNTIF(O5:Q5,".")+COUNTIF(Q6,".")+COUNTIF(O7:Q7,".")+COUNTIF(O6,".")=3,".",""),
     CHOOSE(COUNTIF(O5:Q5,".")+COUNTIF(Q6,".")+COUNTIF(O7:Q7,".")+COUNTIF(O6,".")+1,"","",".",".","","","","","",))))

---

=IF($C$2=1,"",
This part clears the cell in Grid 2 if the reset switch is set to 1.

---

IF($O$2=1,P20,
This is checks the toggle in $O$2. If it is 1 then the cell remains unchanged and is set to it current value (P20).

---

IF(P6="",
     IF(COUNTIF(O5:Q5,".")+COUNTIF(Q6,".")+COUNTIF(O7:Q7,".")+COUNTIF(O6,".")=3,".",""),

This part checks if the cell in the Grid 1 (the mirror grid) is 'dead'. If it is dead then it uses the COUNTIF function to add up all of the living cells in mirror locations in Grid 1 (those with period symbols in them). If the count adds up to 3 the cell becomes alive.

---

CHOOSE(COUNTIF(O5:Q5,".")+COUNTIF(Q6,".")+COUNTIF(O7:Q7,".")+COUNTIF(O6,".")+1,"","",".",".","","","","","",))))
This part activates if the cell is 'alive'. It also uses the same COUNTIF equation to count up the number of living cells in the mirror locations in mirror Grid 1. It then uses the CHOOSE function to choose a final value among all the several Conway rules. 

## Conditional Formatting
To make the grid pretty and the cells light up with nice colours you can set up some conditional formatting.

1. Click on Cell P6 and choose Conditional Formatting in the Home Tab.
2. Choose New Rule.
3. Choose "Use a formula to determine which cells to format"
4. In the formula box type in =P6="." as shown below. Then click the format button and set the format to the colour of your preference.
5. Copy that cell to the other 99 in the grid.
6. Do a similar procedure for Grid 1 and Grid 2.

![](https://steemitimages.com/DQmduKUkyhwyb1nNJBPcrcp4EMjeAb54NXPyDeq5h4NMVBU/image.png)

## Closing Words
This was quite a tricky spreadsheet to get right.

It took me a few hours to adapt the instructions from the [reference](http://www.tushar-mehta.com/publish_train/xl_vba_cases/0906%20conways%20game%20of%20life.shtml) cited below into my own spreadsheet but it was well worth it as I learned a few new useful Excel tricks.

If you set up this spreadsheet yourself, try other patterns and also try to make the grid bigger than 10 x 10.

*Thank you for reading my post.*

## Image Sources
All images in this post are produced by the author.

## Post Sources

This post was inspired by and adapted from this link: http://www.tushar-mehta.com/publish_train/xl_vba_cases/0906%20conways%20game%20of%20life.shtml

Conway's Game of Life (Wikipedia): https://en.wikipedia.org/wiki/Conway's_Game_of_Life
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 60 others
properties (23)
post_id45,102,632
authorprocrastilearner
permlinkkill-time-at-work-with-recreational-math-conway-s-game-of-life
categorysteemstem
json_metadata"{"links": ["https://steemit.com/math/@procrastilearner/kill-time-at-work-with-recreational-math-testing-the-excel-random-function", "https://steemit.com/steemstem/@procrastilearner/kill-time-at-work-with-recreational-math-strange-attractors", "https://steemit.com/steemstem/@procrastilearner/kill-time-at-work-with-recreational-math-let-s-travel-to-alpha-centauri", "https://steemit.com/steemstem/@procrastilearner/kill-time-at-work-with-recreational-math-calculate-sunset-and-sunrise-times", "https://en.wikipedia.org/wiki/Cellular_automaton", "https://en.wikipedia.org/wiki/Conway's_Game_of_Life", "http://www.tushar-mehta.com/publish_train/xl_vba_cases/0906%20conways%20game%20of%20life.shtml"], "format": "markdown", "app": "steemit/0.1", "image": ["https://steemitimages.com/DQmXpRewiotCbKDMn69XhZY5qcXkuNb3pXn4k2jncSXedBy/image.png"], "tags": ["steemstem", "mathematics", "math", "steemeducation", "technology"]}"
created2018-04-24 03:38:51
last_update2018-04-24 04:30:09
depth0
children6
net_rshares2,507,513,237,542
last_payout2018-05-01 03:38:51
cashout_time1969-12-31 23:59:59
total_payout_value14.196 SBD
curator_payout_value3.014 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length10,845
author_reputation10,660,504,989,847
root_title"Kill Time At Work With Recreational Math: Conway's Game of Life"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars0
author_curate_reward""
vote details (124)
@usman119 ·
$0.02
Really beautiful post , at same time I learned MS Excel and mathematics. Thanks bro
👍  
properties (23)
post_id45,102,911
authorusman119
permlinkre-procrastilearner-kill-time-at-work-with-recreational-math-conway-s-game-of-life-20180424t014932555z
categorysteemstem
json_metadata"{"app": "steemit/0.1", "tags": ["steemstem"]}"
created2018-04-24 03:43:06
last_update2018-04-24 03:43:06
depth1
children0
net_rshares4,146,401,678
last_payout2018-05-01 03:43:06
cashout_time1969-12-31 23:59:59
total_payout_value0.020 SBD
curator_payout_value0.004 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length83
author_reputation9,772,372,209,558
root_title"Kill Time At Work With Recreational Math: Conway's Game of Life"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@tts ·
To listen to the audio version of this article click on the play image.
[![](https://s18.postimg.org/51o0kpijd/play200x46.png)](http://ec2-52-72-169-104.compute-1.amazonaws.com/procrastilearner__kill-time-at-work-with-recreational-math-conway-s-game-of-life.mp3)
Brought to you by [@tts](https://steemit.com/tts/@tts/introduction). If you find it useful please consider upvote this reply.
properties (22)
post_id45,106,718
authortts
permlinkre-kill-time-at-work-with-recreational-math-conway-s-game-of-life-20180424t042417
categorysteemstem
json_metadata{}
created2018-04-24 04:24:21
last_update2018-04-24 04:24:21
depth1
children0
net_rshares0
last_payout2018-05-01 04:24:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length388
author_reputation-4,535,933,372,579
root_title"Kill Time At Work With Recreational Math: Conway's Game of Life"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@irelandscape ·
$0.26
Yes, I've been there before trying to guess the outcome from an initial pattern.
There is something about the game of life that keeps bringing back people every now and then.
I wouldn't have thought about using Excel though! :-)
Thanks!
👍  ,
properties (23)
post_id45,135,038
authorirelandscape
permlinkre-procrastilearner-kill-time-at-work-with-recreational-math-conway-s-game-of-life-20180424t082253670z
categorysteemstem
json_metadata"{"app": "steemit/0.1", "tags": ["steemstem"]}"
created2018-04-24 08:22:54
last_update2018-04-24 08:22:54
depth1
children3
net_rshares38,361,718,554
last_payout2018-05-01 08:22:54
cashout_time1969-12-31 23:59:59
total_payout_value0.244 SBD
curator_payout_value0.012 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length236
author_reputation15,369,745,159,352
root_title"Kill Time At Work With Recreational Math: Conway's Game of Life"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@dexterdev ·
$0.06
> I wouldn't have thought about using Excel though! :-)

Exactly! I would have tried some programming language. @procrastilearner showed me how powerful excel is. But anyway, I am using Linux these days.
👍  
properties (23)
post_id45,135,989
authordexterdev
permlinkre-irelandscape-re-procrastilearner-kill-time-at-work-with-recreational-math-conway-s-game-of-life-20180424t082822963z
categorysteemstem
json_metadata"{"app": "steemit/0.1", "users": ["procrastilearner"], "tags": ["steemstem"]}"
created2018-04-24 08:30:18
last_update2018-04-24 08:30:18
depth2
children1
net_rshares8,885,146,453
last_payout2018-05-01 08:30:18
cashout_time1969-12-31 23:59:59
total_payout_value0.044 SBD
curator_payout_value0.012 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length203
author_reputation14,307,229,891,937
root_title"Kill Time At Work With Recreational Math: Conway's Game of Life"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@irelandscape ·
$0.03
Then you ought to post the libreoffice version! 😄
👍  
properties (23)
post_id45,223,901
authorirelandscape
permlinkre-dexterdev-2018424t204746746z
categorysteemstem
json_metadata"{"format": "markdown+html", "app": "esteem/1.6.0", "community": "esteem", "tags": "steemstem"}"
created2018-04-24 19:47:45
last_update2018-04-24 19:47:45
depth3
children0
net_rshares5,002,077,112
last_payout2018-05-01 19:47:45
cashout_time1969-12-31 23:59:59
total_payout_value0.024 SBD
curator_payout_value0.008 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length49
author_reputation15,369,745,159,352
root_title"Kill Time At Work With Recreational Math: Conway's Game of Life"
beneficiaries
0.
weight1,000
accountesteemapp
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@procrastilearner ·
Thx. The motive in my math posts is to use Excel or some other spreadsheet in some unobtrusive manner so you can kill 30 minutes from 4:30 pm to 5:00 pm on a Friday afternoon. 

Why? Everybody has Excel whereas not everyone will have a compiler or interpreted language platform installed.
properties (22)
post_id45,254,776
authorprocrastilearner
permlinkre-irelandscape-re-procrastilearner-kill-time-at-work-with-recreational-math-conway-s-game-of-life-20180425t003340176z
categorysteemstem
json_metadata"{"app": "steemit/0.1", "tags": ["steemstem"]}"
created2018-04-25 00:33:39
last_update2018-04-25 00:33:39
depth2
children0
net_rshares0
last_payout2018-05-02 00:33:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length288
author_reputation10,660,504,989,847
root_title"Kill Time At Work With Recreational Math: Conway's Game of Life"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000