Created
January 7, 2014 16:18
-
-
Save dtothefp/8301783 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FibSequence | |
| def initialize | |
| @first = 0 | |
| @second = 1 | |
| end | |
| def find_fib(n) | |
| i = 2 | |
| print @first.to_s + " " | |
| print @second.to_s + " " | |
| while i <= n.to_i | |
| sum = @first + @second | |
| @first = @second | |
| @second = sum | |
| i += 1 | |
| print sum.to_s + " " | |
| end | |
| sum | |
| end | |
| end | |
| fib = FibSequence.new | |
| puts "\nYour Fib number is #{fib.find_fib(5)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment