ruby ascii golf example


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/usr/bin/env ruby
  2.  
  3. $><<"\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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.