# Re: Golfing a signature

**URL:** <https://www.ruby-forum.com/t/re-golfing-a-signature/59552>\
**Category:** Ruby\
**Created:** [May 4, 2006, 2:37am UTC](https://www.ruby-forum.com/t/re-golfing-a-signature/59552 "2006-05-04T02:37:27Z")\
**Posts on this page:** 1\
**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, 2:37am UTC](https://www.ruby-forum.com/t/re-golfing-a-signature/59552/1 "2006-05-04T02:37:27Z")

</div>

You can shave off another 12 characters by changing the construction of  
the “z” array:

q,z=-1…1,[];q.map{|x|q.map{|y|z\<\<[x,y]}};(z-=[[0,0]]).map{  
q=(m=[-1,0,1])-[0];(m\*2+q).sort.zip(m+q+m).map{

Firstly, z isn’t used after this, so you don’t need to reassign it:

q,z=-1…1,[];q.map{|x|q.map{|y|z\<\<[x,y]}};(z-[[0,0]]).map{

But the whole thing is pointless, as it’s not much better that spelling  
out the entire array:

[[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]].map {

so shorten that with a zip:

[-1,-1,-1,0,0,1,1,1].zip([-1,0,1,-1,1,-1,0,1]).map{

removing some repetition makes it slightly longer:

[-1,-1,-1,0,0,1,1,1].zip((m=[-1,0,1])+(m-[0])+m).map{

but we can fix that:

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

* * *

Also the:

c[i+x[0]][e+x[1]]rescue u

can be rewritten as:

(c[i+x[0]]||[])[e+x[1]]

* * *

I also rejuggled things to move that “\n” so that it made use of the end  
of the line, and There was a reference to " ", which I replaced with f.  
I might have done some other things too, but I don’t have much of a  
memory.

$\>\<\<"\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

That’s 292 characters.
