From: mathew
Date: 2005-11-26T07:52:28+09:00
Subject: Re: recursion
cyberco wrote:
> I'm trying to print every combination of three characters from the
> range (a..z). I thought recursion would be the most elegant solution,
> but that got me quite confused :) Any suggestions?
Definitely not recursion. Consider that your problem is equivalent to
printing every possible 3 digit number in base 26 :-)
Not that you can't do it recursively:
def f(lhs)
if lhs.length == 3
puts lhs
else
for c in 'a'..'z'
f(lhs + c)
end
end
end
f('')
mathew
--
My parents went to the lost kingdom of Hyrule
and all I got was this lousy triforce.