Advertisement
Guest User

Untitled

a guest
Oct 14th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 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.last
  8. end
  9.  
  10. puts "\n enter a number to calculate the Fibonacci sequence"
  11. value = gets.chomp.to_i
  12.  
  13. 10.times do |i|
  14. puts fib(i)
  15. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement