[RUBY] Print a Fibonacci series

By PublicAutopsy in Ruby on 17/06/2009 at 16:52

Views: 861
Tagged: fibonacci, easy, ruby

Starter:

Simple Fibonacci sequence printer, enjoy!

Main Course:

def fib_max(max)
     num1, num2 = 1, 1
     while num1 <= max
          yield num1
          num1, num2 = num2, num1 + num2
     end
end
puts "What number would you like the Fibonacci sequence to go up to?"
fib_max(gets.chomp.to_i) {|f| print f, " "}

Expand Report Code | Install Coda Clip

Please log in to vote.

Compliments to the Chef

No comments yet...

How was your Meal?


  • Allowed HTML: <b><strong><u><i><em><a>

  • Why ask? It helps us stop spam comments.