Module 8 · Recursion
Recursion Patterns: Factorial, Fibonacci, Digits
Free with an accountReading
Kenji wrote Fibonacci exactly as the maths defines it: each number is the sum of the two before it. Four lines, no loop.
Checking what this lesson needs for you…
What is inside Recursion Patterns: Factorial, Fibonacci, Digits
- Digits: the last one with % 10, the rest with / 10
- Print the digits in order: call first, print after
- Euclid's gcd: the answer passes straight up
- Power, and fast power by squaring
- Fibonacci: two calls in every call
- The call tree of fib(5), counted
- Hanoi: the recursion with no simple loop
- One call or two: depth and total are different questions