Anyone familiar with APL?

Chaotic42

Lifer
Jun 15, 2001
34,900
2,061
126
I'm trying to run Conway's Game of Life in One Line of APL (Link) using GNU APL and for whatever reason, I can't get it to work. APL just does nothing. I've tried various values for N (the number of iterations to run), but I've had no luck.

I know it's a long shot, but does anyone have any ideas?

Here's my code:
Code:
⍎'⎕',∈N⍴⊂S←'←⎕←(3=T)∨M∧2=T←⊃+/(V⌽¨⊂M),(V⊖¨⊂M),(V,⌽V)⌽¨(V,V←1¯1)⊖¨⊂M'

Edit: I missed a space between the inputs for the vector V. Oops. Well, it will run for one generation, but will break after that. I run into a system limit (fun_oper) if N is greater than one. Here's the entire program if anyone is interested:

Code:
M←4 4⍴0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
N←2
⍎'⎕',∈N⍴⊂S←'←⎕←(3=T)∨M∧2=T←⊃+/(V⌽¨⊂M),(V⊖¨⊂M),(V,⌽V)⌽¨(V,V←1 ¯1)⊖¨⊂M'
 
Last edited:

j_sauermann

Junior Member
Nov 3, 2013
2
0
0
Hi,

the problem with your code is that for increasing N the statement S will become longer and longer (and sooner or later exceed every system limit).

A better approach is to loop over the statement S using the each operator instead of reshaping S:

⍎¨N⍴⊂S←'⎕←''-''⍪(3=T)∨M∧2=T←⊃+/(V⌽¨⊂M),(V⊖¨⊂M),(V,⌽V)⌽¨(V,V←1 ¯1)⊖¨⊂M'
 

j_sauermann

Junior Member
Nov 3, 2013
2
0
0
and of course M should be updated after each round:

⍎¨N⍴⊂S←'⎕←''-''⍪M←(3=T)∨M∧2=T←⊃+/(V⌽¨⊂M),(V⊖¨⊂M),(V,⌽V)⌽¨(V,V←1 ¯1)⊖¨⊂M'