# Re: Mutually-Recursive Functions

**URL:** <https://www.ruby-forum.com/t/re-mutually-recursive-functions/106243>\
**Category:** Ruby\
**Created:** [June 7, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/re-mutually-recursive-functions/106243 "2007-06-07T20:18:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [June 7, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/re-mutually-recursive-functions/106243/1 "2007-06-07T20:18:15Z")

</div>

From: Gavin K.  
Sent: Thursday, June 07, 2007 12:10 PM

> > # accepts numeric column 1 through 256
> > 
> > if leastSD == 0  
> > Not as efficient, but simpler:  
> > puts “%3d =\> %s” % [n, n2a\_col( n ).inspect]  
> > }
> 
> #=\> 0 =\> nil  
> #=\> 1 =\> “A”  
> #=\> 2 =\> “B”  
> #=\> 26 =\> “Z”  
> #=\> 27 =\> “AA”  
> #=\> 250 =\> “IP”  
> #=\> 255 =\> “IU”  
> #=\> 256 =\> nil

But speaking of efficiency, here’s an auto-caching hash that only  
calculates the column name once for each number. The only ‘downside’ is  
that asking for the name of column 200 the first time fills in the  
values for columns 199 down to the previously greatest column.

COL\_NAME = Hash.new{ |h,n|  
if n==1  
h[n] = ‘A’  
elsif (2…255).include?( n )  
h[n] = h[n-1].succ  
end  
}

[0, 1, 2, 26, 27, 250, 255, 256].each{ |n|  
puts “%3d =\> %s” % [n, COL\_NAME[ n].inspect ]  
}

#=\> 0 =\> nil  
#=\> 1 =\> “A”  
#=\> 2 =\> “B”  
#=\> 26 =\> “Z”  
#=\> 27 =\> “AA”  
#=\> 250 =\> “IP”  
#=\> 255 =\> “IU”  
#=\> 256 =\> nil
