Quest 8: Fibonacci - The Golden Sequence
Explore Natureโs Most Beautiful Mathematical Pattern
๐ QUEST 8 | Difficulty: Intermediate | Time: 5 minutes
๐ Complexity Level: Intermediate โญโญ
Builds on fundamental concepts from earlier quests. Best for students who have completed Quests 1-6 or have some basic programming experience. This introduces algorithmic thinking and patterns.
๐ Introduction: Natureโs Secret Code
Youโre exploring an ancient temple when you notice something amazing:
- A spiral seashell ๐ - The arrangement of sunflower seeds ๐ป - The branching of trees ๐ณ - The curve of a nautilus shell ๐ฆ
All of these follow the same mysterious pattern: the Fibonacci sequence!
๐ข Story Time: In 1202, mathematician Leonardo Fibonacci described a sequence of numbers that appears everywhere in nature. Each number is the sum of the two before it. This simple rule creates one of the most beautiful patterns in mathematicsโฆ and youโre about to code it!
๐ก Explanation: The Fibonacci Sequence
The Fibonacci sequence starts with 0 and 1. Each next number is the sum of the previous two:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144...
0 + 1 = 1
1 + 1 = 2
1 + 2 = 3
2 + 3 = 5
3 + 5 = 8
5 + 8 = 13
...and so on!
๐ The Pattern:
Given a position n in the sequence: - F(0) = 0 - F(1) = 1 - F(n) = F(n-1) + F(n-2)
Example: - F(6) = F(5) + F(4) - F(6) = 5 + 3 - F(6) = 8
In nature: The ratio between consecutive Fibonacci numbers approaches the โGolden Ratioโ (โ1.618), which appears in art, architecture, and nature!
๐ฎ Activity: Generate Fibonacci Sequence
Letโs create the Fibonacci sequence using different methods:
๐ฏ Challenge:
- Generate the first 20 Fibonacci numbers
- Find the 10th Fibonacci number (remember: sequence starts at position 0!)
- Calculate the sum of the first 10 Fibonacci numbers
๐จโ๐ป Code Example: Fibonacci in Action
Letโs explore interesting properties of the sequence:
๐ก Fun Fibonacci Facts:
- In Nature: Pinecones, pineapples, and flower petals often have Fibonacci numbers!
- In Art: The golden ratio (from Fibonacci) is used in painting and architecture
- Even/Odd Pattern: Every 3rd Fibonacci number is even!
- Square Sum: F(n)ยฒ + F(n+1)ยฒ = F(2n+1)
- Divisibility: F(n) is divisible by F(m) if n is divisible by m
๐งฉ Puzzle Time!
Can you spot the pattern and predict what this prints?
๐ Solution Explained:
The even Fibonacci numbers are:
Even Fibonacci numbers:
[0, 2, 8, 34, 144]
Positions of even numbers:
F(0) = 0
F(3) = 2
F(6) = 8
F(9) = 34
F(12) = 144
The Pattern: Every 3rd Fibonacci number is even!
Why? Letโs trace the even/odd pattern: - F(0) = 0 (even) - F(1) = 1 (odd) - F(2) = 1 (odd) - F(3) = 2 (even) - F(4) = 3 (odd) - F(5) = 5 (odd) - F(6) = 8 (even)
Rule: odd + odd = even, even + odd = odd, odd + even = odd
So the pattern repeats: even, odd, odd, even, odd, oddโฆ
Every 3rd position (0, 3, 6, 9โฆ) is even!
๐ฎ Bonus: Recursive Fibonacci
Thereโs another way to calculate Fibonacci - using recursion (a function that calls itself):
๐ฏ Key Takeaways
โจ Quest 8 Complete! โจ
Youโve learned:
โ
The Fibonacci sequence: each number is the sum of the previous two
โ
Starts with 0, 1, then 1, 2, 3, 5, 8, 13, 21โฆ
โ
Can be generated using loops or recursion
โ
Appears in nature, art, and architecture
โ
Ratio of consecutive numbers approaches Golden Ratio (โ1.618)
โ
Every 3rd Fibonacci number is even
Next Quest: Ready to organize data? Try Quest 9: Sorting!
๐ Try This at Home!
Create a Fibonacci visualizer:
def fibonacci_bar_chart(n):
"""Display Fibonacci numbers as a bar chart"""
fib = fibonacci_loop(n)
print("Fibonacci Bar Chart:")
for i, num in enumerate(fib):
if num == 0:
bar = ""
else:
bar = "โ" * num
print(f"F({i:2d}) = {num:3d} | {bar}")
fibonacci_bar_chart(10)Or find Fibonacci numbers in a range:
def is_fibonacci(num):
"""Check if a number is in Fibonacci sequence"""
a, b = 0, 1
while b < num:
a, b = b, a + b
return b == num
# Test numbers
for n in [1, 2, 3, 4, 5, 8, 10, 13, 20, 21]:
if is_fibonacci(n):
print(f"{n} is a Fibonacci number! โ")
else:
print(f"{n} is not a Fibonacci number โ")๐ฑ Amazing Work! Youโve discovered one of mathematicsโ most beautiful patterns! ๐บ