From: vanjac12@... (Van Jacques) Date: 2003-12-02T08:02:20+09:00 Subject: Re: ruby game of life program vanjac12@yahoo.com (Van Jacques) wrote in message news:<70ae81fd.0312010423.7757e2c8@posting.google.com>... > "Josef 'Jupp' SCHUGT" wrote in message news:<20031129174431.GB2320@jupp%gmx.de>... I decided to handle the edges by making the grid into a torus, using mod NN, where I set NN = grid edge, N = NN - 1, in Josef's notation. Then the part of the program that decides that next generation becomes 0.upto(N) do |row| 0.upto(N) do |column| neighbors = 0 -1.upto(1) do |row_offset| -1.upto(1) do |column_offset| unless row_offset == 0 and column_offset == 0 i = (row+row_offset) % NN j = (column+column_offset) % NN neighbors += tos[i][j] end end end if tos[row][column] == 0 tng[row][column] = (neighbors == 3) ? 1 : 0 else tng[row][column] = (neighbors == 2 or neighbors == 3) ? 1 : 0 end end end ============ Since mod NN connects top and bottom, and LHS with RHS, we can do all the rows and columns from 0 to N = NN - 1. I also used a new pattern and more steps or generations. With NN = 11 = # of rows and cols., I used the initial condition know as an "acorn"; tos[4][4] = tos[5][6] = tos[6][3] = tos[6][4] = 1 tos[6][7] = tos[6][8] = tos[6][9] = 1 and increased to # of steps to 40. The pattern is much more interesting, and becomes stable at step 34. If one increases NN to 20, and # of steps to several hundred, the behavior is far more complex. The variety of behaviors of even simple games of life is amazing. I recommend this as a practice program for anyone learning to program.