Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 230428

Submitted on 14 Apr 2013 by andrea84

Correct

59Size
Leading solution size is 11.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
X = fib_seq(145);
assert(isequal(X(end),144) && length(X)==12)
n =
     3
n =
     4
n =
     5
n =
     6
n =
     7
n =
     8
n =
     9
n =
    10
n =
    11
n =
    12
n =
    13
n =
    14
fib =
     1     1     2     3     5     8    13    21    34    55    89   144
2
Pass
 
%%
X = fib_seq(4196);
assert(isequal(X(end),4181) && length(X)==19)
n =
     3
n =
     4
n =
     5
n =
     6
n =
     7
n =
     8
n =
     9
n =
    10
n =
    11
n =
    12
n =
    13
n =
    14
n =
    15
n =
    16
n =
    17
n =
    18
n =
    19
n =
    20
n =
    21
fib =
  Columns 1 through 8
           1           1           2           3           5           8          13          21
  Columns 9 through 16
          34          55          89         144         233         377         610         987
  Columns 17 through 19
        1597        2584        4181
3
Pass
 
%%
X = fib_seq(987419996);
assert(isequal(X(end),701408733) && length(X)==44)
n =
     3
n =
     4
n =
     5
n =
     6
n =
     7
n =
     8
n =
     9
n =
    10
n =
    11
n =
    12
n =
    13
n =
    14
n =
    15
n =
    16
n =
    17
n =
    18
n =
    19
n =
    20
n =
    21
n =
    22
n =
    23
n =
    24
n =
    25
n =
    26
n =
    27
n =
    28
n =
    29
n =
    30
n =
    31
n =
    32
n =
    33
n =
    34
n =
    35
n =
    36
n =
    37
n =
    38
n =
    39
n =
    40
n =
    41
n =
    42
n =
    43
n =
    44
n =
    45
n =
    46
fib =
  Columns 1 through 8
           1           1           2           3           5           8          13          21
  Columns 9 through 16
          34          55          89         144         233         377         610         987
  Columns 17 through 24
        1597        2584        4181        6765       10946       17711       28657       46368
  Columns 25 through 32
       75025      121393      196418      317811      514229      832040     1346269     2178309
  Columns 33 through 40
     3524578     5702887     9227465    14930352    24157817    39088169    63245986   102334155
  Columns 41 through 44
   165580141   267914296   433494437   701408733
4
Pass
 
%%
X = fib_seq(1134903171);
assert(isequal(X(end),1134903170) && length(X)==45)
n =
     3
n =
     4
n =
     5
n =
     6
n =
     7
n =
     8
n =
     9
n =
    10
n =
    11
n =
    12
n =
    13
n =
    14
n =
    15
n =
    16
n =
    17
n =
    18
n =
    19
n =
    20
n =
    21
n =
    22
n =
    23
n =
    24
n =
    25
n =
    26
n =
    27
n =
    28
n =
    29
n =
    30
n =
    31
n =
    32
n =
    33
n =
    34
n =
    35
n =
    36
n =
    37
n =
    38
n =
    39
n =
    40
n =
    41
n =
    42
n =
    43
n =
    44
n =
    45
n =
    46
n =
    47
fib =
   1.0e+09 *
  Columns 1 through 10
    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000
  Columns 11 through 20
    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000
  Columns 21 through 30
    0.0000    0.0000    0.0000    0.0000    0.0001    0.0001    0.0002    0.0003    0.0005    0.0008
  Columns 31 through 40
    0.0013    0.0022    0.0035    0.0057    0.0092    0.0149    0.0242    0.0391    0.0632    0.1023
  Columns 41 through 45
    0.1656    0.2679    0.4335    0.7014    1.1349
5
Pass
 
%%
X = fib_seq(98691443031971);
assert(isequal(X(end),72723460248141) && length(X)==68)
n =
     3
n =
     4
n =
     5
n =
     6
n =
     7
n =
     8
n =
     9
n =
    10
n =
    11
n =
    12
n =
    13
n =
    14
n =
    15
n =
    16
n =
    17
n =
    18
n =
    19
n =
    20
n =
    21
n =
    22
n =
    23
n =
    24
n =
    25
n =
    26
n =
    27
n =
    28
n =
    29
n =
    30
n =
    31
n =
    32
n =
    33
n =
    34
n =
    35
n =
    36
n =
    37
n =
    38
n =
    39
n =
    40
n =
    41
n =
    42
n =
    43
n =
    44
n =
    45
n =
    46
n =
    47
n =
    48
n =
    49
n =
    50
n =
    51
n =
    52
n =
    53
n =
    54
n =
    55
n =
    56
n =
    57
n =
    58
n =
    59
n =
    60
n =
    61
n =
    62
n =
    63
n =
    64
n =
    65
n =
    66
n =
    67
n =
    68
n =
    69
n =
    70
fib =
   1.0e+13 *
  Columns 1 through 10
    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000
  Columns 11 through 20
    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000
  Columns 21 through 30
    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000
  Columns 31 through 40
    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000    0.0000
  Columns 41 through 50
    0.0000    0.0000    0.0000    0.0001    0.0001    0.0002    0.0003    0.0005    0.0008    0.0013
  Columns 51 through 60
    0.0020    0.0033    0.0053    0.0086    0.0140    0.0226    0.0365    0.0591    0.0957    0.1548
  Columns 61 through 68
    0.2505    0.4053    0.6557    1.0610    1.7168    2.7778    4.4946    7.2723