Cody

# Problem 434. Return the Fibonacci Sequence

Solution 1910005

Submitted on 23 Aug 2019 by Eugene Avrutin
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
X = fib_seq(34); assert(isequal(X(end),21) && length(X)==8)

first = 1 second = 0 count = 0 next = 0 count = 1 next = 1 second = 1 first = 1 y = 1 count = 2 next = 2 second = 1 first = 2 y = 1 1 count = 3 next = 3 second = 2 first = 3 y = 1 1 2 count = 4 next = 5 second = 3 first = 5 y = 1 1 2 3 count = 5 next = 8 second = 5 first = 8 y = 1 1 2 3 5 count = 6 next = 13 second = 8 first = 13 y = 1 1 2 3 5 8 count = 7 next = 21 second = 13 first = 21 y = 1 1 2 3 5 8 13 count = 8 next = 34 second = 21 first = 34 y = 1 1 2 3 5 8 13 21

2   Pass
X = fib_seq(35); assert(isequal(X(end),34) && length(X)==9)

first = 1 second = 0 count = 0 next = 0 count = 1 next = 1 second = 1 first = 1 y = 1 count = 2 next = 2 second = 1 first = 2 y = 1 1 count = 3 next = 3 second = 2 first = 3 y = 1 1 2 count = 4 next = 5 second = 3 first = 5 y = 1 1 2 3 count = 5 next = 8 second = 5 first = 8 y = 1 1 2 3 5 count = 6 next = 13 second = 8 first = 13 y = 1 1 2 3 5 8 count = 7 next = 21 second = 13 first = 21 y = 1 1 2 3 5 8 13 count = 8 next = 34 second = 21 first = 34 y = 1 1 2 3 5 8 13 21 count = 9 next = 55 second = 34 first = 55 y = 1 1 2 3 5 8 13 21 34

3   Pass
X = fib_seq(145); assert(isequal(X(end),144) && length(X)==12)

first = 1 second = 0 count = 0 next = 0 count = 1 next = 1 second = 1 first = 1 y = 1 count = 2 next = 2 second = 1 first = 2 y = 1 1 count = 3 next = 3 second = 2 first = 3 y = 1 1 2 count = 4 next = 5 second = 3 first = 5 y = 1 1 2 3 count = 5 next = 8 second = 5 first = 8 y = 1 1 2 3 5 count = 6 next = 13 second = 8 first = 13 y = 1 1 2 3 5 8 count = 7 next = 21 second = 13 first = 21 y = 1 1 2 3 5 8 13 count = 8 next = 34 second = 21 first = 34 y = 1 1 2 3 5 8 13 21 count = 9 next = 55 second = 34 first = 55 y = 1 1 2 3 5 8 13 21 34 count = 10 next = 89 second = 55 first = 89 y = 1 1 2 3 5 8 13 21 34 55 count = 11 next = 144 second = 89 first = 144 y = 1 1 2 3 5 8 13 21 34 55 89 count = 12 next = 233 second = 144 first = 233 y = 1 1 2 3 5 8 13 21 34 55 89 144

4   Pass
X = fib_seq(4196); assert(isequal(X(end),4181) && length(X)==19)

first = 1 second = 0 count = 0 next = 0 count = 1 next = 1 second = 1 first = 1 y = 1 count = 2 next = 2 second = 1 first = 2 y = 1 1 count = 3 next = 3 second = 2 first = 3 y = 1 1 2 count = 4 next = 5 second = 3 first = 5 y = 1 1 2 3 count = 5 next = 8 second = 5 first = 8 y = 1 1 2 3 5 count = 6 next = 13 second = 8 first = 13 y = 1 1 2 3 5 8 count = 7 next = 21 second = 13 first = 21 y = 1 1 2 3 5 8 13 count = 8 next = 34 second = 21 first = 34 y = 1 1 2 3 5 8 13 21 count = 9 next = 55 second = 34 first = 55 y = 1 1 2 3 5 8 13 21 34 count = 10 next = 89 second = 55 first = 89 y = 1 1 2 3 5 8 13 21 34 55 count = 11 next = 144 second = 89 first = 144 y = 1 1 2 3 5 8 13 21 34 55 89 count = 12 next = 233 second = 144 first = 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 count = 13 next = 377 second = 233 first = 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 count = 14 next = 610 second = 377 first = 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 count = 15 next = 987 second = 610 first = 987 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 count = 16 next = 1597 second = 987 first = 1597 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 count = 17 next = 2584 second = 1597 first = 2584 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 count = 18 next = 4181 second = 2584 first = 4181 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 count = 19 next = 6765 second = 4181 first = 6765 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

5   Pass
X = fib_seq(987419996); assert(isequal(X(end),701408733) && length(X)==44)

first = 1 second = 0 count = 0 next = 0 count = 1 next = 1 second = 1 first = 1 y = 1 count = 2 next = 2 second = 1 first = 2 y = 1 1 count = 3 next = 3 second = 2 first = 3 y = 1 1 2 count = 4 next = 5 second = 3 first = 5 y = 1 1 2 3 count = 5 next = 8 second = 5 first = 8 y = 1 1 2 3 5 count = 6 next = 13 second = 8 first = 13 y = 1 1 2 3 5 8 count = 7 next = 21 second = 13 first = 21 y = 1 1 2 3 5 8 13 count = 8 next = 34 second = 21 first = 34 y = 1 1 2 3 5 8 13 21 count = 9 next = 55 second = 34 first = 55 y = 1 1 2 3 5 8 13 21 34 count = 10 next = 89 second = 55 first = 89 y = 1 1 2 3 5 8 13 21 34 55 count = 11 next = 144 second = 89 first = 144 y = 1 1 2 3 5 8 13 21 34 55 89 count = 12 next = 233 second = 144 first = 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 count = 13 next = 377 second = 233 first = 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 count = 14 next = 610 second = 377 first = 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 count = 15 next = 987 second = 610 first = 987 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 count = 16 next = 1597 second = 987 first = 1597 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 count = 17 next = 2584 second = 1597 first = 2584 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 count = 18 next = 4181 second = 2584 first = 4181 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 count = 19 next = 6765 second = 4181 first = 6765 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 count = 20 next = 10946 second = 6765 first = 10946 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 count = 21 next = 17711 second = 10946 first = 17711 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 count = 22 next = 28657 second = 17711 first = 28657 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 count = 23 next = 46368 second = 28657 first = 46368 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 count = 24 next = 75025 second = 46368 first = 75025 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 count = 25 next = 121393 second = 75025 first = 121393 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 count = 26 next = 196418 second = 121393 first = 196418 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 count = 27 next = 317811 second = 196418 first = 317811 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 27 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 count = 28 next = 514229 second = 317811 first = 514229 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 28 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 count = 29 next = 832040 second = 514229 first = 832040 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 29 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 count = 30 next = 1346269 second = 832040 first = 1346269 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 count = 31 next = 2178309 second = 1346269 first = 2178309 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 Column 31 1346269 count = 32 next = 3524578 second = 2178309 first = 3524578 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 Columns 31 through 32 1346269 2178309 count = 33 next = 5702887 second = 3524578 first = 5702887 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 Columns 31 through 33 1346269 2178309 3524578 count = 34 next = 9227465 second = 5702887 first = 9227465 y = Columns 1 through 15 ...

6   Pass
X = fib_seq(1134903171); assert(isequal(X(end),1134903170) && length(X)==45)

first = 1 second = 0 count = 0 next = 0 count = 1 next = 1 second = 1 first = 1 y = 1 count = 2 next = 2 second = 1 first = 2 y = 1 1 count = 3 next = 3 second = 2 first = 3 y = 1 1 2 count = 4 next = 5 second = 3 first = 5 y = 1 1 2 3 count = 5 next = 8 second = 5 first = 8 y = 1 1 2 3 5 count = 6 next = 13 second = 8 first = 13 y = 1 1 2 3 5 8 count = 7 next = 21 second = 13 first = 21 y = 1 1 2 3 5 8 13 count = 8 next = 34 second = 21 first = 34 y = 1 1 2 3 5 8 13 21 count = 9 next = 55 second = 34 first = 55 y = 1 1 2 3 5 8 13 21 34 count = 10 next = 89 second = 55 first = 89 y = 1 1 2 3 5 8 13 21 34 55 count = 11 next = 144 second = 89 first = 144 y = 1 1 2 3 5 8 13 21 34 55 89 count = 12 next = 233 second = 144 first = 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 count = 13 next = 377 second = 233 first = 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 count = 14 next = 610 second = 377 first = 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 count = 15 next = 987 second = 610 first = 987 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 count = 16 next = 1597 second = 987 first = 1597 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 count = 17 next = 2584 second = 1597 first = 2584 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 count = 18 next = 4181 second = 2584 first = 4181 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 count = 19 next = 6765 second = 4181 first = 6765 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 count = 20 next = 10946 second = 6765 first = 10946 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 count = 21 next = 17711 second = 10946 first = 17711 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 count = 22 next = 28657 second = 17711 first = 28657 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 count = 23 next = 46368 second = 28657 first = 46368 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 count = 24 next = 75025 second = 46368 first = 75025 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 count = 25 next = 121393 second = 75025 first = 121393 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 count = 26 next = 196418 second = 121393 first = 196418 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 count = 27 next = 317811 second = 196418 first = 317811 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 27 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 count = 28 next = 514229 second = 317811 first = 514229 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 28 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 count = 29 next = 832040 second = 514229 first = 832040 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 29 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 count = 30 next = 1346269 second = 832040 first = 1346269 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 count = 31 next = 2178309 second = 1346269 first = 2178309 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 Column 31 1346269 count = 32 next = 3524578 second = 2178309 first = 3524578 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 Columns 31 through 32 1346269 2178309 count = 33 next = 5702887 second = 3524578 first = 5702887 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 Columns 31 through 33 1346269 2178309 3524578 count = 34 next = 9227465 second = 5702887 first = 9227465 y = Columns 1 through 15 ...

7   Pass
X = fib_seq(98691443031971); assert(isequal(X(end),72723460248141) && length(X)==68)

first = 1 second = 0 count = 0 next = 0 count = 1 next = 1 second = 1 first = 1 y = 1 count = 2 next = 2 second = 1 first = 2 y = 1 1 count = 3 next = 3 second = 2 first = 3 y = 1 1 2 count = 4 next = 5 second = 3 first = 5 y = 1 1 2 3 count = 5 next = 8 second = 5 first = 8 y = 1 1 2 3 5 count = 6 next = 13 second = 8 first = 13 y = 1 1 2 3 5 8 count = 7 next = 21 second = 13 first = 21 y = 1 1 2 3 5 8 13 count = 8 next = 34 second = 21 first = 34 y = 1 1 2 3 5 8 13 21 count = 9 next = 55 second = 34 first = 55 y = 1 1 2 3 5 8 13 21 34 count = 10 next = 89 second = 55 first = 89 y = 1 1 2 3 5 8 13 21 34 55 count = 11 next = 144 second = 89 first = 144 y = 1 1 2 3 5 8 13 21 34 55 89 count = 12 next = 233 second = 144 first = 233 y = 1 1 2 3 5 8 13 21 34 55 89 144 count = 13 next = 377 second = 233 first = 377 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 count = 14 next = 610 second = 377 first = 610 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 count = 15 next = 987 second = 610 first = 987 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 count = 16 next = 1597 second = 987 first = 1597 y = 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 count = 17 next = 2584 second = 1597 first = 2584 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 count = 18 next = 4181 second = 2584 first = 4181 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 count = 19 next = 6765 second = 4181 first = 6765 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 count = 20 next = 10946 second = 6765 first = 10946 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 count = 21 next = 17711 second = 10946 first = 17711 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 count = 22 next = 28657 second = 17711 first = 28657 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 count = 23 next = 46368 second = 28657 first = 46368 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 count = 24 next = 75025 second = 46368 first = 75025 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 count = 25 next = 121393 second = 75025 first = 121393 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 count = 26 next = 196418 second = 121393 first = 196418 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 count = 27 next = 317811 second = 196418 first = 317811 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 27 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 count = 28 next = 514229 second = 317811 first = 514229 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 28 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 count = 29 next = 832040 second = 514229 first = 832040 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 29 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 count = 30 next = 1346269 second = 832040 first = 1346269 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 count = 31 next = 2178309 second = 1346269 first = 2178309 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 Column 31 1346269 count = 32 next = 3524578 second = 2178309 first = 3524578 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 Columns 31 through 32 1346269 2178309 count = 33 next = 5702887 second = 3524578 first = 5702887 y = Columns 1 through 15 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Columns 16 through 30 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 Columns 31 through 33 1346269 2178309 3524578 count = 34 next = 9227465 second = 5702887 first = 9227465 y = Columns 1 through 15 ...

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!