Forum: Ruby Re: Golfing a signature.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1c1e3bdfe006a22214102fcd6434a012?d=identicon&s=25 Daniel Sheppard (Guest)
on 2006-05-04 02:40
(Received via mailing list)
Also, somewhere along the line you changed what the program was actually
doing - originally you produced a 20x21 grid, but that got reduced to a
20x20.

I used this to make sure I didn't change the program during golfing:

require 'stringio'
out = ""
$stdout = StringIO.new(out)
srand(1);

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

$stdout = STDOUT

#uncomment this to reset the content of the file.
#File.open("monkeys","w") {|f| f << out }

raise "Different" unless File.read("monkeys") === out
This topic is locked and can not be replied to.