# Dawson Community College Programming & Coding Worksheet

Description

1 attachmentsSlide 1 of 1attachment_1attachment_1

Unformatted Attachment Preview

You have been hired by Yellowstone National Park to implement Conway’s ‘Game of Life’
(https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) because they believe that this ‘game’ might provide
some insight into the development of patterns in microbial mats in the various hot-springs. Conway’s game
begins with the creation of a random, two-dimensional matrix containing only ‘O’ and ‘1’, and the matrix is
meant to represent a two-dimensional surface that contains open spots, i.e., the ‘O’ spots, and spots occupied
by microbes, i.e., the ‘l’ spots. The code below creates a two-dimensional matrix (size is numX by numy) of
zeros and ones, and then uses matplotlib’s spy() function to plot the matrix.
import matplotlib.pyplot as plt
import numpy
numX, numY = 20, 20
x = numpy.random.randint(0,2, (numX, numy)) # Initial population
for iter in range(3):
# iterate through 3 growth/death cycles
# Your code should go here!
plt. figure(iter) # create a new figure for this iteration
plt.spy(x, markersize=10) # plots the pattern each cycle/iteration
=
You’ve been hired to implement the rules of Conway’s Game of Life so that the final plot reflects the population
after 3 growth/death cycles (i.e., 3 iterations). Each iteration (i.e., inside the 3 iteration loop), your code should
go through each spot on the surface (i.e., each entry in the matrix) except for the outer edges using a double for-
loop (e.g., for J in range(numY-1):, then a second loop inside this loop, for I in range(numX-1):). For each spot,
count the number of living neighbors (above, below, left, and right). The total sum of neighbors must be in the
range 0-4, and, since each spot is either a 0 or 1, just adding the values of the four neighbors will tell you the
total number of neighbors. YNP recommends, for example:
neighbors X[I-1,3] + x[I+1,J] + x[I,J-1] + x[I,J+1]
Once the number of neighbors is calculated, you can implement the rules of the Game of Life (see wikipedia)
using ‘if’ statements. For rule #1, which states that any living microbe on a spot dies if it has less than 2 living
neighbors, an if-statement would be:
if neighbors < 2 and x[I,J] == 1: x[I,J] = 0 # Oh no! It died ! Please write a memo to Yellowstone National Park summarizing the algorithm you developed, describe the results, including at least one output plot, and, finally, including you code in the appendix. Rule #2 states that if the number of neighbors is greater than 3, the spot dies from starvation. The third and final rules states that if there are exactly 3 neighbors, the spot should be occupied (i.e., set to 1). Hint: We are not exactly implementing Conway's Game of Life because we are skipping the outer edges and we are updating the matrix as we step through it. The original algorithm updated every spot simultaneously. If you try to copy some online Python code for Conway's Game of Life, it will probably implement this original algorithm, which is not correct here, and you will be committing academic misconduct so please do not copy it. Purchase answer to see full attachment Explanation & Answer: 1 Worksheet User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

## Reviews, comments, and love from our customers and community:

### Article Writing

Keep doing what you do, I am really impressed by the work done.

Researcher

### PowerPoint Presentation

I am speechless…WoW! Thank you so much!

#### Stacy V.

Part-time student

### Dissertation & Thesis

This was a very well-written paper. Great work fast.

Student

### Annotated Bibliography

I love working with this company. You always go above and beyond and exceed my expectations every time.

Student

### Book Report / Review

I received my order wayyyyyyy sooner than I expected. Couldn’t ask for more.

Student

### Essay (Any Type)

On time, perfect paper

Student

### Case Study

Awesome! Great papers, and early!

#### Kaylin Green

Student

Thank you Dr. Rebecca for editing my essays! She completed my task literally in 3 hours. For sure will work with her again, she is great and follows all instructions

Researcher

### Critical Thinking / Review

Extremely thorough summary, understanding and examples found for social science readings, with edits made as needed and on time. Transparent

Customer

Perfect!

Student