What is the ruby way to do this without recursion?
Thanks,
Phil C
class FactorialCases
attr_reader :count
attr :cases, true
def initialize(str)
@pat = str
@cases = []
compute_cases(str)
end
private
def compute_cases(str)
size = str.size
1.upto(size) do
@pat[0..(size - 1)] = str
if size > 2 then
compute_cases(str.slice(0..-2))
else
@cases << @pat.dup
end
str = str.slice(-1,1) + str.chop
end
str
end
end
a = FactorialCases.new("123")
a.cases.each { |value| print "Factorial pattern = ", value, "\n" }
print "total ", a.cases.size, "\n"