Re: Mutually-Recursive Functions

From: bbiker [mailto:[email protected]]
Sent: Thursday, June 07, 2007 12:00 PM

I am not exactly sure what the OP was trying to do … except that it
has to do with Columns in Excel. It does seems to me to be fairly
complicated. If this off topic, please excuse.

[snip]

leastSD = num_col % 26
end
Not as efficient, but simpler:

def n2a_col( num_col )
if (1…255).include?( num_col )
a = ‘A’
( num_col-1 ).times{ a = a.succ }
a
end
end

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

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