3. Fibonacci Sequence
This app will introduce the Compute Module - that is, doing some activities without any user interactions repeatedly until a certain condition is met.
We will implement the Fibonacci Sequence. If you are not familiar with it, here is the Wikipedia page describing it: https://en.wikipedia.org/wiki/Fibonacci_sequence
We will implement this algorithm in a straight forward way - note the {...} in front of the Calc step; this denotes that the step has no user interactions - no data being entered or reported to users.
Let's go.
In Entry, we start by asking our users to enter the value for which we need to calculate the Fibonacci number.
Besides the Fibonacci number itself, we will also provide the sequence up to that number. To do so, we instantiate a list with 0.
Implementing the algorithm
The pseudocode we implement is as follows:
list = {0} while counter < entry if counter does not exist, counter = 1 if f2 does not exist f1 = 1 else f1 = f2 if fib does not exist, f2 = 1 else f2 = fib if fib does not exist then fib = f1 + f2 else fib = 1 list = {list, fib}
This is exactly what we implement in the Calc compute module:
For the calculation of the fibonacci number:
To add to the list:
We repeat the steps above while we satisfy the condition count < entry:
Lastly, we show the results - for example , when entry is 7: