This link has been bookmarked by 6 people . It was first bookmarked on 03 Jun 2008, by Olifante *.
-
17 May 10
James ChoateIf you are not familiar with Convey's Game of Life or APL programming language, I recommend to consult the very short description of APL and the description of Conway's Game of Life. Besides, on this page you will find IBM APL2 interpreter and several lan
-
20 Jun 08
harry palmerAn explanation
If you are not familiar with Convey's Game of Life or APL programming language, I recommend to consult the very short description of APL and the description of Conway's Game of Life. Besides, on this page you will find IBM APL2 interpreter and several language references.
This detailed explanation of the APL program that prints out N generations of the initial configuration M of the Game of Life will also serve as a brief and very informal course in APL.
Before we start to decipher (this seems to be the correct word here) the Life program, let's try to work out the strategy of how to write this program in one line, no matter how impossible it sounds.
Life is a cyclic game by its very nature and - surely - the algorithm implementing this game apparently should consist of several cycles. Thus, the main loop of this program is the flow of the generations. Another loop is the one that scans the matrix to calculate the cells that are dead, alive or newborn. Yet another loop calculates the number of neighbors of every given cell. Now, you think, that's it: we cannot use even a single loop inside one line, let alone three nested loops!
But wait a minute - APL allows us to overcome almost any, even the most desperate situation.
First of all, we don't need a loop to scan the matrix, since APL allows us to work with the whole matrix usually using a single function. The same applies to the number of neighbors. As for the main loop that govenrs the change of generations - there will be no such thing at all!
Let N be a number of generations we want to calculate. We can write down all the loops (that is the subprograms that constitute the body of the loop) as one very long line. Now all we have to do is to execute this line.
It's not good, - says the reader. - What if we need 1000 generations ? Shall we write down 1000 loops that are doing the same thing then ? Absolutely not! As we've said before, all these loops are doing the same thing, so we will just write down only one loop and then APL will help us t -
03 Jun 08
-
30 May 08
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.