Differences between revisions 7 and 14 (spanning 7 versions)
Revision 7 as of 2007-01-11 20:49:35
Size: 1191
Editor: KaiJaeger
Comment:
Revision 14 as of 2007-03-09 08:57:28
Size: 521
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= FunExamples = ## page was renamed from FunExamples
= John Conways`s "Game of Life" =
Line 3: Line 4:
[[TableOfContents]]

== John Conways`s "Game of Life" ==

This dynamic function takes a boolean matrix as argument and return a boolean matrix with the new generation. It is taken from [http://www.dyalog.dk/dfnsdws/n_life.htm Dyalog`s] Website. Note that this website is at the moment ist not supporting Unicode. You should see APL characters with Internet Explorer but not with other browser.
This function takes a boolean matrix as argument and returns a boolean matrix with the new generation.
Line 10: Line 7:
life←{↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}   ∇ nextGeneration←Life currentGeneration
[1] ⍝⍝ Take a matrix of Booleans and returns one
[2] nextGeneration←↑1 currentGeneration∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂currentGeneration
  ∇
Line 13: Line 13:

== Meaning of Life (Hitchhiker`s Guide to the Galaxy) ==

As you might know, the answer to the ultimate question is '''42''', according to [http://en.wikipedia.org/wiki/Douglas_adams Douglas Adams`s] famous book "[http://en.wikipedia.org/wiki/The_Hitchhiker's_Guide_to_the_Galaxy Hitchhiker`s Guide to the Galaxy"]. We do not need a supercomputer and millions of years to proof that. Whatever you specify as right argument to this function:

{{{
MeaningOfLife←{+.×/⍎⊖⍕⊃¨⊂|⌊-*+○⌈∨.∧/>\</×÷!⌽⍉⍉⌹~⍴⍋⍒,⍟?⍳''≡1↑0⍴∊⍵}
}}}

...will produce a reasonable answer, regardless which type/lenght/depth/rank it is.
See also [http://catpad.net/michael/apl/ Conway's Game of Life in one line of APL]
Line 25: Line 16:

CategoryDyalog
CategoryShowcases

John Conways`s "Game of Life"

This function takes a boolean matrix as argument and returns a boolean matrix with the new generation.

  ∇ nextGeneration←Life currentGeneration
[1] ⍝⍝ Take a matrix of Booleans and returns one
[2]  nextGeneration←↑1 currentGeneration∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂currentGeneration

See also [http://catpad.net/michael/apl/ Conway's Game of Life in one line of APL]


CategoryShowcases

GameOfLife (last edited 2015-01-28 19:11:48 by KaiJaeger)