Skip to content

Instantly share code, notes, and snippets.

@youchan
Last active April 20, 2020 00:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youchan/ff191eed286fab7929a730e61d999e95 to your computer and use it in GitHub Desktop.
Save youchan/ff191eed286fab7929a730e61d999e95 to your computer and use it in GitHub Desktop.
One liner version n Conway's Game of Life
s=30;Array.new((s+2)*(s+2),0).tap{|g|[100,133,163,164,165].each{|i|g[i]=1};100.times{s.times{|y|puts s.times.map{|x|g[x+s+3+y*(s+2)]==1??*:?.}.join};(s*s).times.map{|i|i+=i/s*2;[0,1,2,3,5,6,7,8].map{|x|g[i+x%3+x/3*2+x/3*s]}.sum.then{|x|x==3?1:x==2?g[i+s+3]:0}}.tap{|n|(s*s).times{|i|g[i+s+3+i/s*2]=n[i]}};sleep(0.1);print"\e[#{s}A"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment