RockstarLang / rockstar

Home of the Rockstar programming language
https://codewithrockstar.com/
GNU Affero General Public License v3.0
6.88k stars 223 forks source link

nth-fibonacci example contains an error. #312

Closed MarijnRitzen closed 2 years ago

MarijnRitzen commented 2 years ago

https://github.com/RockstarLang/rockstar/blob/22f6e1b23735e3cc29c430ef491ebcd8039cd598/examples/nth-fibonacci.rock#L18

I think this is one of those bugs that is not so wrong that you notice it. Running it with for example n = 19 gives 2584. This should be 4181. The reason for this is that the author of the algorithm probably thought he was adding the night and my life. However add is for boolean expressions and not for addition. Thus, in his 19th turn, the algorithm does 1597 and 2584 which (because 1597 is truthy) evaluates to 2584. This should be 1597 plus 2584 to get the correct answer of fibonacci(19) == 4181.