Teaching Kids Programming: Videos on Data Structures and Algorithms
We know the Golden Ratio
Quadratic function
Root 1:
Root 2:
We take the positive root which is
We also learned previously that the golden ratio exists in the Fibonacci numbers:
Metal Quadratic Equation
Let’s define the quadratic equation
when
when
when
and so on…
The (positive) root for the metal quadratic equation is:
Pell Number and Silver Ratio
Let’s take the Silver Ratio Equation:
We can solve the positive root is
The Pell Numbers are quite similar to Fibonacci numbers except each number in the Pell Number sequence is equal to two times its previous number plus the one before:
where the first two Pell numbers are:
The first few Pell Numbers are: 0, 1, 2, 5, 12, 29, 70, 169, … (if the first two numbers are both 2, then we have Pell-Lucas Numbers)
If we keep going on..
aka.
So, we can use this method to estimate the value of the silver ratio
Compute Pell Number in Recursion
We can implement the Pell Number (similar to Fibonacci Number) in Recursion and then can be improved with memoziation which makes it Dynamic Programming Algorithm (Top Down).
@cache
def pell(n):
if n == 0:
return 0
if n == 1:
return 1
return 2*pell(n - 1) + pell(n - 2)
Most modern compilers will probably optimise this into the iterative manner:
def pell(n):
a, b = 0, 1
for _ in range(n):
a, b = b, 2 * b + a
return a
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm)
Next Post: Teaching Kids Programming - Introduction to Kruskal's Minimum Spanning Tree (Graph Algorithm)