C
cyberco
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? Here's my
(erronous) attempt:
________________________
def addChar(str, level)
('a'..'z').each {|c|
if level == 2
puts str + c
else
str += c
addChar(str, level + 1)
end
}
end
addChar("", 0)
range (a..z). I thought recursion would be the most elegant solution,
but that got me quite confused Any suggestions? Here's my
(erronous) attempt:
________________________
def addChar(str, level)
('a'..'z').each {|c|
if level == 2
puts str + c
else
str += c
addChar(str, level + 1)
end
}
end
addChar("", 0)