Skip to content

Instantly share code, notes, and snippets.

@youchan
Last active November 8, 2024 05:04
Show Gist options
  • 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;g=[0]*(s+2)**2;[100,133,163,164,165].each{g[_1]=1};100.times{s.times{|y|puts s.times.map{g[_1+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{g[i+_1%3+_1/3*2+_1/3*s]}.sum.then{_1==3?1:_1==2?g[i+s+3]:0}}.tap{|n|(s*s).times{g[_1+s+3+_1/s*2]=n[_1]}};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