Ad
  • Custom User Avatar

    My solution is passing all of the test cases, but does not pass the falsifiable test. I'm certain that what I'm doing fits the given pattern, so I'm not quite sure what I'm missing.

    Also, it is telling me

    expected: 150
    but got: 0
    -3

    Is that a (negative) 3 ? I tried using absolute value, which doesn't help.

  • Custom User Avatar

    There is no reason to keep the entire array around.

    def fibonacci(n, arr=[0, 1])
    return n if (0..1).include? n
    return arr.reduce(&:+) if n == 2
    fibonacci(n - 1, [arr[1], arr.reduce(&:+)])
    end