Cody

Problem 43016. Find the next Fibonacci number

Solution 2812810

Submitted on 9 Aug 2020 by Ramesh Kumar V
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));

m = 1 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 ind = 1×6 logical array 0 0 0 0 0 1 z1 = 8 z = 8

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

m = 3 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 ind = 1×7 logical array 0 0 0 0 0 0 1 z1 = 13 z = 13 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 ind = 1×10 logical array 0 0 0 0 0 0 0 0 0 1 z1 = 55 z = 13 55 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 ind = 1×10 logical array 0 0 0 0 0 0 0 0 0 1 z1 = 55 z = 13 55 55

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

m = 5 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 ind = 1×7 logical array 0 0 0 0 0 0 1 z1 = 13 z = 13 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 y = 1 1 2 3 5 8 13 21 34 55 89 y = 1 1 2 3 5 8 13 21 34 55 89 144 ind = 1×12 logical array 0 0 0 0 0 0 0 0 0 0 0 1 z1 = 144 z = 13 144 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 y = 1 1 2 3 5 8 13 21 34 55 89 y = 1 1 2 3 5 8 13 21 34 55 89 144 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 17 987 1597 ind = 1×17 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 z1 = 1597 z = 13 144 1597 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 y = 1 1 2 3 5 8 13 21 34 55 89 y = 1 1 2 3 5 8 13 21 34 55 89 144 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 17 987 1597 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 18 987 1597 2584 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 19 987 1597 2584 4181 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 20 987 1597 2584 4181 6765 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 21 987 1597 2584 4181 6765 10946 ind = 1×21 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 z1 = 10946 z = 13 144 1597 10946 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 y = 1 1 2 3 5 8 13 21 34 55 89 y = 1 1 2 3 5 8 13 21 34 55 89 144 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 17 987 1597 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 18 987 1597 2584 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 19 987 1597 2584 4181 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 20 987 1597 2584 4181 6765 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 21 987 1597 2584 4181 6765 10946 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 22 987 1597 2584 4181 6765 10946 17711 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 23 987 1597 2584 4181 6765 10946 17711 28657 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 24 987 1597 2584 4181 6765 10946 17711 28657 46368 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 25 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 26 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 ind = 1×26 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 z1 = 121393 z = 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));

m = 9 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 y = 1 1 2 3 5 8 13 21 34 55 89 y = 1 1 2 3 5 8 13 21 34 55 89 144 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 ind = 1×14 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 1 z1 = 377 z = 377 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 y = 1 1 2 3 5 8 13 21 34 55 89 y = 1 1 2 3 5 8 13 21 34 55 89 144 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 ind = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 z1 = 987 z = 377 987 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 y = 1 1 2 3 5 8 13 21 34 55 89 y = 1 1 2 3 5 8 13 21 34 55 89 144 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 17 987 1597 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 18 987 1597 2584 ind = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 z1 = 2584 z = 377 987 2584 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 y = 1 1 2 3 5 8 13 21 34 55 89 y = 1 1 2 3 5 8 13 21 34 55 89 144 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 17 987 1597 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 18 987 1597 2584 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 19 987 1597 2584 4181 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 20 987 1597 2584 4181 6765 ind = 1×20 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 z1 = 6765 z = 377 987 2584 6765 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 y = 1 1 2 3 5 8 13 21 34 55 89 y = 1 1 2 3 5 8 13 21 34 55 89 144 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 17 987 1597 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 18 987 1597 2584 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 19 987 1597 2584 4181 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 20 987 1597 2584 4181 6765 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 21 987 1597 2584 4181 6765 10946 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 22 987 1597 2584 4181 6765 10946 17711 ind = 1×22 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 z1 = 17711 z = 377 987 2584 6765 17711 k = 0 y = 1 1 y = 1 1 2 y = 1 1 2 3 y = 1 1 2 3 5 y = 1 1 2 3 5 8 y = 1 1 2 3 5 8 13 y = 1 1 2 3 5 8 13 21 y = 1 1 2 3 5 8 13 21 34 y = 1 1 2 3 5 8 13 21 34 55 y = 1 1 2 3 5 8 13 21 34 55 89 y = 1 1 2 3 5 8 13 21 34 55 89 144 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 17 987 1597 y = Columns 1 through 1...