the definition for conway's game of life function that is usually given
(rosettacode)
life
(_3 _3 (+/ e. 3 + 0 , 4&{)@,;._3 ])@(0 , 0 ,~ 0 ,. 0 ,.~ ])
but
(3 3 (+/ e. 3+0,4&{)@, ;._3 ])@(0,0,~0,.0,.~]) is not only a bit shorter, its
clearer and in j8 2x faster and with 20x less memory use.
(_3 _3 <;._3 ])@(0 , 0 ,~ 0 ,. 0 ,.~ ]) i.4 4
┌───────┬────────┬────────┬───────┐
│5 4 0 │6 5 4 │7 6 5 │0 7 6 │
│1 0 0 │2 1 0 │3 2 1 │0 3 2 │
│0 0 0 │0 0 0 │0 0 0 │0 0 0 │
├───────┼────────┼────────┼───────┤
│9 8 0 │10 9 8 │11 10 9 │0 11 10│
│5 4 0 │ 6 5 4 │ 7 6 5 │0 7 6│
│1 0 0 │ 2 1 0 │ 3 2 1 │0 3 2│
├───────┼────────┼────────┼───────┤
│13 12 0│14 13 12│15 14 13│0 15 14│
│ 9 8 0│10 9 8│11 10 9│0 11 10│
│ 5 4 0│ 6 5 4│ 7 6 5│0 7 6│
├───────┼────────┼────────┼───────┤
│ 0 0 0│ 0 0 0│ 0 0 0│0 0 0│
│13 12 0│14 13 12│15 14 13│0 15 14│
│ 9 8 0│10 9 8│11 10 9│0 11 10│
└───────┴────────┴────────┴───────┘
(3 3 <;._3 ])@(0 , 0 ,~ 0 ,. 0 ,.~ ]) i.4 4
┌───────┬────────┬────────┬───────┐
│0 0 0 │0 0 0 │0 0 0 │0 0 0 │
│0 0 1 │0 1 2 │1 2 3 │2 3 0 │
│0 4 5 │4 5 6 │5 6 7 │6 7 0 │
├───────┼────────┼────────┼───────┤
│0 0 1 │0 1 2 │1 2 3 │ 2 3 0│
│0 4 5 │4 5 6 │5 6 7 │ 6 7 0│
│0 8 9 │8 9 10 │9 10 11 │10 11 0│
├───────┼────────┼────────┼───────┤
│0 4 5│ 4 5 6│ 5 6 7│ 6 7 0│
│0 8 9│ 8 9 10│ 9 10 11│10 11 0│
│0 12 13│12 13 14│13 14 15│14 15 0│
├───────┼────────┼────────┼───────┤
│0 8 9│ 8 9 10│ 9 10 11│10 11 0│
│0 12 13│12 13 14│13 14 15│14 15 0│
│0 0 0│ 0 0 0│ 0 0 0│ 0 0 0│
└───────┴────────┴────────┴───────┘
so is _3 _3 ,: something that previous versions of J performed better with?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm