11 comments

[ 4.8 ms ] story [ 38.2 ms ] thread
Off the top of my head, some simple ways to make this shorter:

  * Use 0...s*s instead of 0..s*s-1
  * Use 0..s*s instead of 0...s*s (overrunning g doesn't matter much)
  * Use count{|x|x} instead of compact.count
  * Get rid of ||nil (because count{|x|x} ignores all falsy values)
  * Get rid of the brackets around g[i]&&n==2
  * Use [g[i-s-1,3],g[i-1],g[i+1],g[i+s-1,3]].flatten instead of [[g[i-s-1],g[i-s],g[i-s+1],g[i-1],g[i+1],g[i+s-1],g[i+s],g[i+s+1]]
  * Use -1..s*s instead of 0..s*s and substitute i+1 for i (i.e. g[i+1] instead of g[i], but [g[i-s,3],g[i],g[i+2],g[i+s,3]] instead of [g[i-s-1,3],g[i-1],g[i+1],g[i+s-1,3]])
It's all ASCII... If you're using octets for each character, you can definitely still squeeze a few bytes out of that.
(comment deleted)
None of these examples ran with 1.9.3 :\",
OP here. I'm pretty sure they run in 1.9.3 because I wrote them in it.
And in APL:

life←{ ↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ }