# Re: Golfing a signature

**URL:** <https://www.ruby-forum.com/t/re-golfing-a-signature/94465>\
**Category:** Ruby\
**Created:** [May 4, 2006, 3:56am UTC](https://www.ruby-forum.com/t/re-golfing-a-signature/94465 "2006-05-04T03:56:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dasch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dasch](https://www.ruby-forum.com/u/dasch)\
**Post date:** [May 4, 2006, 3:56am UTC](https://www.ruby-forum.com/t/re-golfing-a-signature/94465/1 "2006-05-04T03:56:50Z")

</div>

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|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

272 Characters. I think I’ll quit now.

---

<div class="post-metadata">

**Author:** ![dasch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dasch](https://www.ruby-forum.com/u/dasch)\
**Post date:** [May 4, 2006, 8:30am UTC](https://www.ruby-forum.com/t/re-golfing-a-signature/94465/2 "2006-05-04T08:30:25Z")

</div>

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! 🙂

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