Return to Snippet

Revision: 1280
at September 27, 2006 10:10 by gdonald


Updated Code
#!/usr/bin/env ruby

$><<"\e[2J";s,o,f,c,u=20,"#"," ";b,m=(z=0..s).map{z.map{(rand<0.3)?o:f}},[-1,0,1]*3;until c==b;c=b.map{|z|z.dup};$><<"\e[H"<<b.map{|x|x*f}*"";s.times{|i|s.times{|e|n=(m.sort.zip(m)-[[0,0]]).select{|x,z|o==(c[i+x]||[])[e+z]}.size;n!=2?b[i][e]=n==3?o:f:f}};sleep 0.2;end

Revision: 1279
at September 27, 2006 10:10 by gdonald


Initial Code
#!/usr/bin/env ruby

$><<"\e[2J";s,o,f,c,u=20,"#"," ";b,m=(z=0..s).map{z.map{(rand<0.3)?o:f}},[-1,0,1]*3;until c==b;c=b.map{|z|z.dup};$><<"\e[H"<<b.map{|x|x*f}*"";s.times{|i|s.times{|e|n=(m.sort.zip(m)-[[0,0]]).select{|x,z|o==(c[i+x]||[])[e+z]}.size;n!=2?b[i][e]=n==3?o:f:f}};sleep 0.2;end

Initial URL

                                

Initial Description

                                

Initial Title
ruby ascii golf example

Initial Tags

                                

Initial Language
Ruby