• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Anyone familiar with APL?

Chaotic42

Lifer
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:
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'
 
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'
 
Back
Top