Guest User

Untitled

a guest
Jul 19th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. ;; Since the base case of the first 2 Fibonacci numbers being one and two is important to our definition
  2. ;; We will start with them already in the list
  3. ;; (list is 1 indexed)
  4. fibs = [1,2]
  5.  
  6. while(fibs.getLast() <= 4,000,000) ;; We only want the fibonacci numbers not over 4 million, so we will stop after that
  7. length = fibs.getLength() ;; We need the length of the list to address the last two elements
  8. ;; This adds the next fibonacci number to the list.
  9. ;; It is just the sum of the previous two
  10. ;; Since we are building the list starting with the first Fibonacci number, we already have the previous two
  11. ;; Instead of calculating them we just look them up
  12. fibs.append(fibs.get(length) + fibs.get(length-1))
  13. end
  14.  
  15. 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