Module: JobInterview::Fibonacci

Included in:
Answer
Defined in:
lib/job_interview/fibonacci.rb

Instance Method Summary collapse

Instance Method Details

#fib(n, *args) ⇒ Object

args should be the strategy to be used (one of :iterative, :recursive) Defaults to recursive



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/job_interview/fibonacci.rb', line 9

def fib(n, *args)
  if args && args.include?(:iterative)
    iterative_fib(n)
  elsif args && args.include?(:matrix)
    matrix_fib(n)
  else
    ## TODO: make this efficient
    return Array.new(n) {|i| recursive_fib(i + 1) }

  end

end