The Fibonacci sequence exceeds a certain target value. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: The Fibonacci sequence exceeds a certain target value. (/showthread.php?tid=86765) |
The Fibonacci sequence exceeds a certain target value. - leusiam - 02-16-2023 I'm attempting to construct a Fibonacci series and list each element. I'd want to specify that no element in the Fibonacci sequence should be bigger than a certain number. I wrote a function called myFib to construct this list and passed a number of 20 as a parameter, anticipating that my Fibonacci list would only contain values less than 20. My loop terminates after appending element 21, and I'm attempting to figure out what I'm doing wrong. Once I get this to work, I'd want to do it for a target value of 2000000, therefore I'm attempting to figure out the mechanism before setting a huge target amount. Code: def myFib(max_count): I'm receiving the following output: Code: [1, 1, 2, 3, 5, 8, 13, 21] Could someone assist me with this issue? According to this article that I've read, you should add a condition in the code that breaks the while loop so that no value exceeds the max count variable. Is that right? |