
-----------------------------------
riveryu
Wed May 21, 2008 10:30 pm

recursion problems
-----------------------------------
Hey ppl, I want to practice my recursion skills, if any of you have problems please post here...
This may not be just for me. 
Yes, I googled it...
(am i in the right section here or should i post somewhere else?)

The ones I know are ones from the Recursion tutorial here at the forum except for...

1. factorials, which are positive integers which is the product of all the positive integers before it. (wikipedia says non-negative because 0 is a factorial of 0).
ex. 5 x 4 x 3 x 2 x 1 = 120, denoted as !5, with that exclaimation
write a program that finds the factorial of a given number using recursion

2. Squaring
write a program that can replace the n**e function in Turing, where as n is a real number and e is the exponent . using recursion
Thanks a lot.

Answers here... Highlight / select them with your mouse to see

fcn square (number : real, exponent : real) : real
    if exponent = 1 then
        result number
    else
        result number * square (number, exponent - 1)
    end if
end square
put square (2,2)

fcn fact (number : int) : int
    if number = 1 then
        result number
    else
        result number * fact (number - 1)
    end if
end fact
put fact(5)

-----------------------------------
r691175002
Wed May 21, 2008 10:46 pm

Re: recursion problems
-----------------------------------
Fibonacci numbers, where each number is the sum of the previous two:
0 1 1 2 3 5 8 13...

Fibonacci numbers with memoization ( http://en.wikipedia.org/wiki/Memoization )

Something more advanced would be graph search problems such as depth first and breadth first searches.

-----------------------------------
riveryu
Thu May 22, 2008 11:12 am

RE:recursion problems
-----------------------------------
hey, sry but that was already mentioned the Recursion Tutorial...all of what you said...
