Re: Golfing a signature


#1

And another bit:

b[i][e]=(n==2?b[i][e]:n==3?o:f

becomes:

n!=2?b[i][e]=n==3?o:f:f


The z array can be reduced further

q=(m=[-1,0,1])-[0];(m*2+q).sort.zip(m+q+m).map{

becomes:

m=[-1,0,1]*3;(m.sort.zip(m)-[[0,0]]).map{


Then, the calculation of n can be improved by using separate variables:

n=((m.sort.zip(m)-[[0,0]]).map{|x|(c[i+x[0]]||[])[e+x[1]]}-[f,u]).size

becomes:

n=((m.sort.zip(m)-[[0,0]]).map{|z,x|(c[i+z]||[])[e+x]}-[f,u]).size

and then, turn it into a select statement:

n=(m.sort.zip(m)-[[0,0]]).select{|x,z|o==(c[i+x]||[])[e+z]}.size


This leaves:

$><<"\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|xf}*”
";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

272 Characters. I think I’ll quit now.


#2

The b.map{|x|x*" "} cannot be changed to b.map{|x|x*f} becasue f and o
should be able to change, and not effect it.
Thanks alot guys, youve been a great help!
I realize I have lots more to learn! :slight_smile:

Joey
http://eachmapinject.com
(c=“amBleQ==\n”).unpack("#{c[1…1]}*").pop