Conway's Game of Life in J
I thought I'd give J (link) a try and implemented Conway's Game of Life in it.
Code:
step =: ((]+.&(3&=)+)(+/@(((4&{.,(_4&{.))(>,{,~<i:1))&|.)))~
Sample:
step =: ((]+.&(3&=)+)(+/@(((4&{.,(_4&{.))(>,{,~<i:1))&|.)))~
[ f =: 5 5 $ 0 1 0 0 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0
0 0 1 0 0
1 1 1 0 0
0 0 0 0 0
0 0 0 0 0
step f
0 0 0 0 0
1 0 1 0 0
0 1 1 0 0
0 1 0 0 0
0 0 0 0 0
Changelog
- 2017/12/31: Slightly improved version, made step verb monadic
- 2013/06/23: Initial version