Created
March 21, 2017 08:38
-
-
Save take-five/0f1350388db04d7b7ca003750ad2ffa4 to your computer and use it in GitHub Desktop.
backend-dev interview code example
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 FibonacciCalculator | |
def initialize | |
end | |
def run | |
number = ARGV.first | |
puts "Fibonacci number for N=#{number}: #{fib(number.to_i)}" | |
end | |
private | |
def fib(n) | |
case | |
when n == 0 then 0 | |
when n <= 2 then 1 | |
else fib(n - 2) + fib(n - 1) | |
end | |
end | |
end | |
FibonacciCalculator.new.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment