How to think like a programmer A programmers guide
Know what you want to make It may vary, but right now, we want something to make that will make you think like a programmer. So we will make a code that prints out the Fibonacci Series
Fibonacci Series Invented back in 200 BC, a work by Pingala and named after a Italian Mathematician called Leonardo of Pisa aka, Fibonacci. Leonardo of Pisa Pingala
What is Fibonacci Series? By definition, the Fibonacci series is a sequence of the 2 preceding numbers, starting from 0 and 1. So, 0 + 1 = 1 As the sum is 1, we will add it to the second number, 1- 1 + 1 = 2 As the sum is 2, we will add it to the second number, 1- 2 + 1 = 3 As the sum is 3, we will add it to the second number, 2- 3 + 2 = 5 And so on
Why is it special? These squares have their side length as their Fibonacci number. Notice something
Why is it special? It has the same pattern as the special number, Φ (phi) or otherwise known as the, “Golden Ratio”
IT’S EVERYWHERE
So how do we write the Fibonacci Series Know the steps of thinking like a programmer. Understand the problem Reframe it in programming terms Understand logic Refine your logic until it is perfect Code
The problem is to Find the next number by summing up the previous 2 numbers.
Reframe it in programming terms Take the sum of the current sum and the previous number.
Understand the logic Take the sum of the current sum and the previous number. We can use variables to do so.
Understand the logic a+b =c b+c =d c+d =e So on and on and on.
Refine the logic a+b =c b+c =d c+d =e So on and on and on. But this will take like a million variables. So maybe something simpler?
Refine the logic What about this? a+b =c Change the value of a to b, and the value of b to c a+b =c Repeat the loop
Much simpler right? What about this? a+b =c Change the value of a to b, and the value of b to c a+b =c Repeat the loop