Advertisement
Guest User

Untitled

a guest
Oct 16th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. def fib(n)
  2. return n if n < 2
  3. vals = [0, 1]
  4. (n-1).times do
  5. vals.push(vals[-1] + vals[-2])
  6. end
  7. return vals
  8. end
  9.  
  10.  
  11. puts "\n enter a number integer or float to calculate the Fibonacci sequence"
  12. num = gets.chomp.to_i
  13.  
  14. loop do |n|
  15. puts fib(n)
  16. break if vals >= num.to_i
  17. end
  18.  
  19. puts "you have reached your destination"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement