Well, this was fun. I made a function that calculates the x-th fibonacci number in FiM++.
( public class "A letter about fibonacci numbers" { )
Dear Princess Celestia : A letter about fibonacci numbers
( double fibonacci(double position) { )
I learned the fibonacci number with a number using a number position:
( if (position == 0) { return 1; } )
If position was 0 then:
Then you get 1!
That's what I would do.
( if (position == 1) { return 1; } )
If position was 1 then:
Then you get 1!
That's what I would do.
( double "the previous one" = fibonacci(position - 1); )
Did you know that the previous one is a number?
The previous one is the fibonacci number using position minus 1!
( double "the one before the previous one" = fibonacci(position - 2); )
Did you know that the one before the previous one is a number?
The one before the previous one is the fibonacci number using position minus 2!
( double "the resulting number" = "the previous one" + "the one before the previous one"; )
Did you know that the resulting number is a number?
The resulting number is the previous one added to the one before the previous one!
( return "the resulting number"; )
Then you get the resulting number!
( } )
That's all about the fibonacci number.
( main() { )
Today I learned how to calculate fibonacci numbers recursively:
( double "the position of the desired number"; )
Did you know that the position of the desired number is a number?
( "the position of the desired number" = read(); )
I heard the position of the desired number.
( write(fibonacci("the position of the desired number")); )
I sang the fibonacci number using the position of the desired number.
( } )
That's all about how to calculate fibonacci numbers recursively.
( } )
Your faithful student, Twilight Sparkle