Numerit[WIN32][1700][1703]## fast-life qffffff)@ffffffi@fffffvq@?@ffffff9@?@ffffff9@ffffff)@ffffff)@         Times New RomanArialSymbol Courier New I xwwww[V@wwwww[V@ac@@t@t@ >==>>?? 0.010.01 0.010.0103X *%@@genvvvpvvvpvvvpvvvpvvvpvvvpvvv vvv.The Game of Lifevvvvvv generation: ! vvv  7vvv (see the text below for details about the game's rules)vvv vvv The game of life is a cellular automaton defined on a two-dimensional grid of cells and governed by a simple set of rules. It was invented in 1970 by the mathematician John Conway.vvv Each of the cells in the 2-d grid can be in one of two states: alive or dead. Beginning with any given initial pattern of live cells, one can employ Conway's rules in order to determine the behavior of the cells over a number of generations. vvv Whether a cell is born, survives, or dies is determined by the number of live neighbors it has. Each cell has eight neighbors (four on its sides and four in the corners). The rules for survival, death, and birth are as follows:Pvvv.  Survival: if a live cell has two or three live neighbors it survives.]vvv.  Death: if a live cell has less than two or more than three live neighbors it dies.Tvvv.  Birth: if a dead (empty) cell has exactly three live neighbors it is born.vvv vvv In this implementation a finite 2-d grid is represented by the matrix '#a'. Each cell in '#a' has four possible values and matching colors (given in the color table '#c'):;vvv.  0: A dead (empty) cell - in the background color(vvv.  1: A cell just born - in blue7vvv.  2: An old cell with two neighbors - in green7vvv.  3: An old cell with three neighbors - in redvvv tvvv The function #nextgen(a,pa) receives the current state in the matrix '#a' and the previous state in the matrix 'p#a' and returns the next generation in the matrix '#a'. In each generation the 2-d grid is scanned to find the number of neighbors of each cell (kept in the matrix '#b'). Then, the new generation is created using the survival rules.vvv vvv #There is a lot of material about the Game of Life on the Internet and you are encouraged to explore it. See for example: !*http://www.math.com/students/wonders/life/life.htmlvvv vvv  q8ffffff)@j@fffffvq@?@ffffff9@?@ffffff9@ffffff)@ffffff)@         Times New RomanArialSymbol Courier New 4` This sample program demonstrates an implementation)` of The Game of Life with a finite grid.*` The grid can be initialized with various.` patterns. Currently we've defined 4 possible` initial patterns:` * A random pattern` * The R-pentomino pattern` * The Glider pattern!` * The Queen Bee Shuttle pattern.` You can easily add more patterns to the list3` (see the reference at the end of the document for` more information).2` The pattern is selected by the Input instruction)` into the variable init_pat (see below).)` To start: press the Run button (or F9).` Termination:,` 1. If the parameter num_gen (below) is > 0+` the program runs for num_gen generations.,` 2. If num_gen = 0 the program tests if the*` next generation is equal to the previous+` generation; when this happens it will run1` for 20 more generations and stop. In most cases-` the pattern enters an oscillatory state and.` switches between two patterns, so by setting0` num_gen to 0 we test for such a case (and also1` for the case when the pattern is steady). Note,0` however, that in many cases the pattern enters0` an oscillatory state with a cycle greater than.` 2 generations (i.e., it repeats itself every,` 3 generations or more). Such a case is not-` identified and the program continues to run,` indefinitely (similar to the next option)./` 3. If num_gen is < 0 the program runs forever.` so you must stop it manually by pressing the` Stop button (or F5). num_gen = 0` Grid initialization -"` Choose from the given selection: ` 0: Random` 1: R-pentomino ` 2: Glider` 3: Queen Bee Shuttleinit_pat = 3 ` default pattern;input "Select an initial pattern (between 0 to 3)" init_patn = 80 ` dimensiona[n,n]:0 ` gridpa = a ` previous"if init_pat = 0 ` a random pattern randinit(a)else` define the initial pattern case init_pat1: ` the R-pentomino patternai =0,1,01,1,00,1,12: ` the glider patternai =1,0,10,1,10,1,0"3: ` the queen-bee-shuttle patternai = 1,1,0,00,0,1,00,0,0,10,0,0,10,0,0,10,0,1,01,1,0,0else:&message("Life","Illegal pattern ")stopinit(a,ai) ` insert to a ` color codec =)230,240,250 ` background: dead (empty)0,0,255 ` blue: just born%0,192,0 ` green: has 2 neighbors$255,0,0 ` red: has 3 neighbors(report ` make the report visible$gen = 0 ` generations counter%refresh ` show initial patternwait 2 ` 2 sec. delay` runloop4` If the pattern repeats itself and 'num_gen' is 00` (see above) we stop after 20 more generations./` Note that the function nextgen() returns TRUE%` if next pattern = previous pattern.2if nextgen(a,pa) if num_gen = 0 num_gen = gen + 20gen += 1refreshif gen = num_gen break+`------------------------------------------func init(a,ai) ` insert ai at the center of ani = length(ai)nirows = ni[1]nicols = ni[2]na = length(a) nrows = na[1] ncols = na[2]ir1 = round((nrows-nirows)/2)ic1 = round((ncols-nirows)/2)ir = ir1 to ir1+nirows-1ic = ic1 to ic1+nicols-1clear aa[ir,ic] = ai+`------------------------------------------func randinit(a)` define a random pattern randomize;a[%n,%n]:0.6 ` must be > 0.5; determines no. of 0's and 1's a = round(rand(a)) ` 0's and 1's` clear margins a[1,*] = 0 a[%n,*] = 0 a[*,1] = 0 a[*,%n] = 0+`------------------------------------------func nextgen(a,pa):` Define the next generation according to Conway's rules7` and return it in 'a' which is the current generation.8` 'a' is kept in 'pa' as the previous generation for the ` next round.8` The matrix 'aa', defined below, is the same as 'a' but7` with all live cells set to 1; it is used for counting;` the number of neighbors of each cell using a single array8` operation (see below). Note that in our implementation;` live cells may have any value between 1 to 3 (see below),.` so we can't use 'a' itself for this purpose. aa[%n,%n]:0where a <> 0 aa = 1` Count the neighbors:/` First define array indices (i,j,im,jm,ip,jp). i = 2 to %n-1j = i im = i - 1jm = im ip = i + 1jp = ip4` Now use the array indices to define the matrix 'b'6` that specifies the number of neighbors of each cell,` in a single array operation. b[%n,%n]:0bb[i,j] = aa[im,jm] + aa[i,jm] + aa[ip,jm] + aa[im,j] + aa[ip,j] + aa[im,jp] + aa[i,jp] + aa[ip,jp]*` Define the next generation matrix ('na') na[%n,%n]:07` The cells in the next generation matrix 'na' may have7` one of four values (0,1,2,3); this is not part of the9` game's rules (for which a value of 1 for all live cells:` is sufficient) but we do it in order to make the display ` colorful and more informative.%where a = 0 and b = 3 na = 1 ` birth6where a <> 0 and b = 2 na = 2 ` survival - 2 neighbors6where a <> 0 and b = 3 na = 3 ` survival - 3 neighbors6repat = min(pa = na) `` true if ALL elements are equal#pa = a `` current becomes previousa = na `` next becomes current return repat(c:\program files\numerit\numerit modules num_gen init_patna paaic gen   % - .  p0 1  4 ,2 4  \75 <?68  ^86?9       6 ^86?@      6 ^86?G             6?R  TV  <?Y     _a bc  fk  <7 \7  @l Nmn  \76 6  7&L;xP randinit randinita //  04 ,  4 / 04  4 / 04 > init initaaininirowsnicolsnanrowsncolsir1ic1iric Mrt u 4v 4w x 4y 4z  A C {  A C | @ A e } @ A e ~  4 > nextgen nextgenapaaaijimjmipjpbnarepat /  04 ,  ] ? / 0 A e   A   @  /  04 ,   4  4  4@  4@  4@  4@  4@  4@  4@ /  04 ,   \ \`  ?  ] \`  ?  ] \`  ?  \    => 03@*Select an initial pattern (between 0 to 3)80T@1?2@LifeIllegal pattern 230l@240n@250@o@255o@192h@204@0.6333333?