Re: Golfing a signature


#1

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|xf}"
";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