When using input x
, I'm trying to iterate through the alphabet through to that point so, if I put in 44, I'll iterate to 18 from this method.
I can see a lot of methods on SO for iteration a..z, a..zzz, etc, but less for iteration to position x and outputting the associated letters. Is there a ruby method for flipping an input letter to a number within a dynamic range?
def get_num(x)
pos = x%26
(1..pos).each do |c|
puts c
#outputs letter for position c
# end
end
get_num(44) # => Expected: 44%26 = 18; iterate 1 to 18 (pos) to get A..R list as output.
(1..pos).each do |c|
how about1.upto pos do |c|
?