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 318429

Submitted on 12 Sep 2013 by James

Correct

107Size
Leading solution size is 37.
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
 
%%
a = [1 5 3 11 7 2 4 9];
stride = 2;
assert(isequal(skip_sequence_stride(a),stride))
b =
     1     2     3     4     5     7     9    11
2
Pass
 
%%
a = [1:5:20 23:3:42 2:9:100];
stride = 9;
assert(isequal(skip_sequence_stride(a),stride))
b =
  Columns 1 through 16
     1     2     6    11    16    20    23    26    29    32    35    38    41    47    56    65
  Columns 17 through 19
    74    83    92
3
Pass
 
%%
a = [2:2:22 13:17];
a = a(randperm(length(a)));
stride = 2;
assert(isequal(skip_sequence_stride(a),stride))
b =
     2     4     6     8    10    12    13    14    15    16    17    18    20    22
4
Pass
 
%%
a = 37:5:120;
a = a(randperm(length(a)));
stride = 5;
assert(isequal(skip_sequence_stride(a),stride))
b =
  Columns 1 through 16
    37    42    47    52    57    62    67    72    77    82    87    92    97   102   107   112
  Column 17
   117
5
Pass
 
%%
a = [1:5 101:10:171 201:205];
a = a(randperm(length(a)));
stride = 10;
assert(isequal(skip_sequence_stride(a),stride))
b =
  Columns 1 through 16
     1     2     3     4     5   101   111   121   131   141   151   161   171   201   202   203
  Columns 17 through 18
   204   205
6
Pass
 
%%
a = [7:17:302 primes(300)];
a = sort(a);
stride = 17;
assert(isequal(skip_sequence_stride(a),stride))
b =
  Columns 1 through 16
     2     3     5     7    11    13    17    19    23    24    29    31    37    41    43    47
  Columns 17 through 32
    53    58    59    61    67    71    73    75    79    83    89    92    97   101   103   107
  Columns 33 through 48
   109   113   126   127   131   137   139   143   149   151   157   160   163   167   173   177
  Columns 49 through 64
   179   181   191   193   194   197   199   211   223   227   228   229   233   239   241   245
  Columns 65 through 76
   251   257   262   263   269   271   277   279   281   283   293   296