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.
Sign in to read
This lesson is free, with an account
An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.
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