Cody

# Problem 43016. Find the next Fibonacci number

Solution 1932156

Submitted on 12 Sep 2019 by Binh Nguyen Cong
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
n = 6; out = 8; assert(isequal(next_fibonacci(n),out));

first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 y = 8

2   Pass
n = [12 40 50]; out = [13 55 55]; assert(isequal(next_fibonacci(n),out));

first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 y = 13 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 y = 13 55 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 y = 13 55 55

3   Pass
n = 10.^(1:5); out = [13 144 1597 10946 121393]; assert(isequal(next_fibonacci(n),out));

first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 y = 13 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 y = 13 144 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 next = 610 second = 377 first = 610 next = 987 second = 610 first = 987 next = 1597 second = 987 first = 1597 y = 13 144 1597 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 next = 610 second = 377 first = 610 next = 987 second = 610 first = 987 next = 1597 second = 987 first = 1597 next = 2584 second = 1597 first = 2584 next = 4181 second = 2584 first = 4181 next = 6765 second = 4181 first = 6765 next = 10946 second = 6765 first = 10946 y = 13 144 1597 10946 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 next = 610 second = 377 first = 610 next = 987 second = 610 first = 987 next = 1597 second = 987 first = 1597 next = 2584 second = 1597 first = 2584 next = 4181 second = 2584 first = 4181 next = 6765 second = 4181 first = 6765 next = 10946 second = 6765 first = 10946 next = 17711 second = 10946 first = 17711 next = 28657 second = 17711 first = 28657 next = 46368 second = 28657 first = 46368 next = 75025 second = 46368 first = 75025 next = 121393 second = 75025 first = 121393 y = 13 144 1597 10946 121393

4   Pass
n = round(7.^(3:.5:7)); out = [377 987 2584 6765 17711 46368 121393 317811 832040]; assert(isequal(next_fibonacci(n),out));

first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 y = 377 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 next = 610 second = 377 first = 610 next = 987 second = 610 first = 987 y = 377 987 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 next = 610 second = 377 first = 610 next = 987 second = 610 first = 987 next = 1597 second = 987 first = 1597 next = 2584 second = 1597 first = 2584 y = 377 987 2584 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 next = 610 second = 377 first = 610 next = 987 second = 610 first = 987 next = 1597 second = 987 first = 1597 next = 2584 second = 1597 first = 2584 next = 4181 second = 2584 first = 4181 next = 6765 second = 4181 first = 6765 y = 377 987 2584 6765 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 next = 610 second = 377 first = 610 next = 987 second = 610 first = 987 next = 1597 second = 987 first = 1597 next = 2584 second = 1597 first = 2584 next = 4181 second = 2584 first = 4181 next = 6765 second = 4181 first = 6765 next = 10946 second = 6765 first = 10946 next = 17711 second = 10946 first = 17711 y = 377 987 2584 6765 17711 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 next = 610 second = 377 first = 610 next = 987 second = 610 first = 987 next = 1597 second = 987 first = 1597 next = 2584 second = 1597 first = 2584 next = 4181 second = 2584 first = 4181 next = 6765 second = 4181 first = 6765 next = 10946 second = 6765 first = 10946 next = 17711 second = 10946 first = 17711 next = 28657 second = 17711 first = 28657 next = 46368 second = 28657 first = 46368 y = 377 987 2584 6765 17711 46368 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 next = 610 second = 377 first = 610 next = 987 second = 610 first = 987 next = 1597 second = 987 first = 1597 next = 2584 second = 1597 first = 2584 next = 4181 second = 2584 first = 4181 next = 6765 second = 4181 first = 6765 next = 10946 second = 6765 first = 10946 next = 17711 second = 10946 first = 17711 next = 28657 second = 17711 first = 28657 next = 46368 second = 28657 first = 46368 next = 75025 second = 46368 first = 75025 next = 121393 second = 75025 first = 121393 y = 377 987 2584 6765 17711 46368 121393 first = 1 second = 0 next = 0 next = 1 second = 1 first = 1 next = 2 second = 1 first = 2 next = 3 second = 2 first = 3 next = 5 second = 3 first = 5 next = 8 second = 5 first = 8 next = 13 second = 8 first = 13 next = 21 second = 13 first = 21 next = 34 second = 21 first = 34 next = 55 second = 34 first = 55 next = 89 second = 55 first = 89 next = 144 second = 89 first = 144 next = 233 second = 144 first = 233 next = 377 second = 233 first = 377 next = 610 second = 377 first = 610 next = 987 second = 610 first = 987 next = 1597 second = 987 first = 1597 next = 2584 second = 1597 first = 2584 next = 4181 second = 2584 first = 4181 next = 6765 second = 4181 first = 6765 next = 10946 second = 6765 first = 10946 next = 17711 second = 10946 first = 17711 next = 28657 second = 17711 first = 28657 next = 46368 second = 28657 first = 46368 next = 75025 second = 46368 first = 75025 next = 121393 second = 75025 fi...