home *** CD-ROM | disk | FTP | other *** search
- .MCD 20000 0
- .CMD PLOTFORMAT logs=0,0 subdivs=1,1 size=5,15 type=l
- .CMD FORMAT rd=d ct=10 im=i et=3 zt=15 pr=3 mass length time charge
- .CMD SET ORIGIN 0
- .CMD SET TOL 0.001000
- .CMD MARGIN 0
- .CMD LINELENGTH 70
- .CMD SET PRNCOLWIDTH 4
- .CMD SET PRNPRECISION 1
- .CMD FILENAME data1 data1
- .CMD FILENAME data2 data2
- .CMD FILENAME f start
- .CMD FILENAME life life
- .TXT 1 0 1 36
- a1,35,33,34
- John Horton Conway's game of LIFE
- .TXT 2 0 10 32003
- b10,32002,70,600
- LIFE begins with a two-dimensional array of ones and zeros. Ones are
- "live" cells; zeroes are "dead" cells. In each step, or generation,
- the array changes based on rules about how many neighbors a cell must
- have to survive, to be born, or to die.
- INSTRUCTIONS: 1. Type [Esc] DOS COPY START.PRN LIFE.PRN [Enter].
- 2. Go to READ equation by typing [Esc] go 30 [Enter].
- 3. For each generation, put the cursor on the "READ"
- equation on line 30 and press [F9]. MathCAD shows the
- results in graphs at the end of the document.
- .EQN 11 1 1 9
- n:10
- .TXT 0 11 1 40
- a1,40,38,39
- Size of one side of the field of play.
- .EQN 2 -11 1 17
- x1:0;n+1
- .EQN 0 19 1 12
- x:1;n
- .TXT 0 15 3 43
- a3,42,40,124
- Range variables for the matrix. (Row and
- column 0 and row and column n+1 are the
- edges. They are set to and remain zero.)
- .EQN 1 -34 1 17
- y1:0;n+1
- .EQN 0 19 1 12
- y:1;n
- .EQN 3 -19 2 13
- F[(x1,y1):0
- .EQN 0 16 1 8
- S:F
- .TXT 0 18 1 32
- a1,31,53,30
- Initialize matricese to zero.
- .EQN 3 -34 1 16
- dx:-1,0;1
- .TXT 0 16 1 34
- a1,33,31,32
- Ranges used to count neighbors.
- .EQN 1 -16 1 16
- dy:-1,0;1
- .TXT 2 -1 2 75
- a2,74,74,127
- Now read the matrix from a data file. To calculate each generation, put
- cursor on the following READ equation and press [F9].
- .EQN 3 0 1 20
- F:READPRN(life)
- .TXT 0 48 1 18
- a1,17,22,16
- ... Read matrix
- .EQN 1 -48 1 48
- live(F,S):if(F≈1,(S≥3)*(S≤4),(S≈3))
- .TXT 0 48 1 30
- a1,29,29,28
- ... Life and death function
- .EQN 1 -48 4 30
- S[(x,y):dx$dy$F[(x+dx,y+dy)
- .EQN 1 37 2 31
- G[(x1,y1):live(F[(x1,y1),S[(x1,y1))
- .EQN 3 -37 1 21
- WRITEPRN(life):G
- .TXT 0 49 1 27
- a1,26,28,25
- ... Write updated matrix
- .TXT 2 -49 3 32003
- b3,32002,70,200
- The S array adds up the number of neighbors of elements of the Farray.
- An element stays alive if it has 3 or 4 neighbors, self included.
- Otherwise it dies. It is born if it has exactly 3 neighbors.
- .EQN 4 0 9 29
- n+1&.1&F[(x,y)*y{1,1,8,18,o}@n+1&0&x
- .EQN 0 35 9 29
- n+1&.1&G[(x,y)*y{1,1,8,18,o}@n+1&0&x
- .EQN 12 -35 12 44
- F=?
-