Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; Since the base case of the first 2 Fibonacci numbers being one and two is important to our definition
- ;; We will start with them already in the list
- ;; (list is 1 indexed)
- fibs = [1,2]
- while(fibs.getLast() <= 4,000,000) ;; We only want the fibonacci numbers not over 4 million, so we will stop after that
- length = fibs.getLength() ;; We need the length of the list to address the last two elements
- ;; This adds the next fibonacci number to the list.
- ;; It is just the sum of the previous two
- ;; Since we are building the list starting with the first Fibonacci number, we already have the previous two
- ;; Instead of calculating them we just look them up
- fibs.append(fibs.get(length) + fibs.get(length-1))
- end
- fibs.removeLast() ;; Remove the last element (since it is over 4 million) and we now have a list of all the fibonacci numbers which do not exceed 4 million to do with as we please
Advertisement
Add Comment
Please, Sign In to add comment