← Back to context

Comment by llm_trw

13 days ago

      life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵}

https://aplwiki.com/wiki/John_Scholes%27_Conway%27s_Game_of_...

I'm not sure how you don't call that an eso lang.

Would you prefer something like this numpy then?

  def life(x):
    y = np.array([np.roll(x, -1), np.roll(x, 0),np.roll(x, 1)])
    y = np.array([np.roll(y, -1, 1), np.roll(y, 0, 1),np.roll(y, 1, 1)])
    z = y.sum(1).sum(0)
    a = np.array([3 == z, 4==z])
    c = np.logical_and(np.array([np.ones(x.shape), x]), a)
    return np.logical_or(c[0], c[1])

Video of Scholes building up the life APL expression can be seen here: https://www.youtube.com/watch?v=a9xAKttWgP4