Cody

Problem 317. Find the stride of the longest skip sequence

Solution 41895

Submitted on 15 Feb 2012 by Andrew
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
%% a = [1 5 3 11 7 2 4 9]; stride = 2; assert(isequal(skip_sequence_stride(a),stride))

``` c = 6 c = 7 c = 4 c = 4 c = 3 c = 3 c = 3 a = 2 3 4 5 7 9 11 c = 5 c = 3 c = 3 c = 3 c = 3 c = 3 a = 3 4 5 7 9 11 c = 4 c = 6 c = 4 c = 3 c = 3 a = 4 5 7 9 11 c = 3 c = 3 c = 3 c = 3 a = 5 7 9 11 c = 5 c = 3 c = 3 a = 7 9 11 c = 4 c = 3 a = 9 11 c = 3 a = 11 ```

2   Pass
%% a = [1:5:20 23:3:42 2:9:100]; stride = 9; assert(isequal(skip_sequence_stride(a),stride))

``` c = 3 c = 5 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = Columns 1 through 16 2 6 11 11 16 20 23 26 29 29 32 35 38 38 41 47 Columns 17 through 21 56 65 74 83 92 c = 3 c = 12 c = 12 c = 3 c = 7 c = 3 c = 3 c = 5 c = 5 c = 3 c = 3 c = 4 c = 4 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 a = Columns 1 through 16 6 11 11 16 20 23 26 29 29 32 35 38 38 41 47 56 Columns 17 through 20 65 74 83 92 c = 4 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = Columns 1 through 16 11 11 16 20 23 26 29 29 32 35 38 38 41 47 56 65 Columns 17 through 19 74 83 92 c = 1 c = 3 c = 11 c = 5 c = 5 c = 6 c = 6 c = 3 c = 3 c = 5 c = 5 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 a = Columns 1 through 16 11 16 20 23 26 29 29 32 35 38 38 41 47 56 65 74 Columns 17 through 18 83 92 c = 3 c = 11 c = 5 c = 5 c = 6 c = 6 c = 3 c = 3 c = 5 c = 5 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 a = Columns 1 through 16 16 20 23 26 29 29 32 35 38 38 41 47 56 65 74 83 Column 17 92 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 20 23 26 29 29 32 35 38 38 41 47 56 65 74 83 92 c = 9 c = 5 c = 10 c = 10 c = 3 c = 3 c = 6 c = 6 c = 3 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 a = 23 26 29 29 32 35 38 38 41 47 56 65 74 83 92 c = 8 c = 6 c = 6 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 26 29 29 32 35 38 38 41 47 56 65 74 83 92 c = 7 c = 7 c = 4 c = 3 c = 3 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 29 29 32 35 38 38 41 47 56 65 74 83 92 c = 1 c = 6 c = 5 c = 9 c = 9 c = 3 c = 5 c = 4 c = 3 c = 3 c = 3 c = 3 a = 29 32 35 38 38 41 47 56 65 74 83 92 c = 6 c = 5 c = 9 c = 9 c = 3 c = 5 c = 4 c = 3 c = 3 c = 3 c = 3 a = 32 35 38 38 41 47 56 65 74 83 92 c = 5 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 35 38 38 41 47 56 65 74 83 92 c = 4 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 38 38 41 47 56 65 74 83 92 c = 1 c = 3 c = 8 c = 5 c = 4 c = 3 c = 3 c = 3 a = 38 41 47 56 65 74 83 92 c = 3 c = 8 c = 5 c = 4 c = 3 c = 3 c = 3 a = 41 47 56 65 74 83 92 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 47 56 65 74 83 92 c = 7 c = 4 c = 3 c = 3 c = 3 a = 56 65 74 83 92 c = 6 c = 4 c = 3 c = 3 a = 65 74 83 92 c = 5 c = 3 c = 3 a = 74 83 92 c = 4 c = 3 a = 83 92 c = 3 a = 92 ```

3   Pass
%% a = [2:2:22 13:17]; a = a(randperm(length(a))); stride = 2; assert(isequal(skip_sequence_stride(a),stride))

``` c = 12 c = 7 c = 5 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 4 6 8 10 12 13 14 14 15 16 16 17 18 20 22 c = 11 c = 6 c = 5 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 6 8 10 12 13 14 14 15 16 16 17 18 20 22 c = 10 c = 6 c = 4 c = 4 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 8 10 12 13 14 14 15 16 16 17 18 20 22 c = 9 c = 5 c = 4 c = 4 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 10 12 13 14 14 15 16 16 17 18 20 22 c = 8 c = 4 c = 5 c = 5 c = 4 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 a = 12 13 14 14 15 16 16 17 18 20 22 c = 8 c = 7 c = 7 c = 4 c = 4 c = 4 c = 4 c = 3 c = 3 c = 3 a = 13 14 14 15 16 16 17 18 20 22 c = 7 c = 7 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 14 14 15 16 16 17 18 20 22 c = 1 c = 6 c = 6 c = 6 c = 4 c = 4 c = 3 c = 3 a = 14 15 16 16 17 18 20 22 c = 6 c = 6 c = 6 c = 4 c = 4 c = 3 c = 3 a = 15 16 16 17 18 20 22 c = 5 c = 5 c = 3 c = 3 c = 3 c = 3 a = 16 16 17 18 20 22 c = 1 c = 4 c = 5 c = 3 c = 3 a = 16 17 18 20 22 c = 4 c = 5 c = 3 c = 3 a = 17 18 20 22 c = 3 c = 3 c = 3 a = 18 20 22 c = 4 c = 3 a = 20 22 c = 3 a = 22 ```

4   Pass
%% a = 37:5:120; a = a(randperm(length(a))); stride = 5; assert(isequal(skip_sequence_stride(a),stride))

``` c = 18 c = 10 c = 7 c = 6 c = 5 c = 4 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 42 47 52 57 62 67 72 77 82 87 92 97 102 107 112 117 c = 17 c = 9 c = 7 c = 5 c = 5 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 47 52 57 62 67 72 77 82 87 92 97 102 107 112 117 c = 16 c = 9 c = 6 c = 5 c = 4 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 52 57 62 67 72 77 82 87 92 97 102 107 112 117 c = 15 c = 8 c = 6 c = 5 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 57 62 67 72 77 82 87 92 97 102 107 112 117 c = 14 c = 8 c = 6 c = 5 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 62 67 72 77 82 87 92 97 102 107 112 117 c = 13 c = 7 c = 5 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 67 72 77 82 87 92 97 102 107 112 117 c = 12 c = 7 c = 5 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 a = 72 77 82 87 92 97 102 107 112 117 c = 11 c = 6 c = 5 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 a = 77 82 87 92 97 102 107 112 117 c = 10 c = 6 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 a = 82 87 92 97 102 107 112 117 c = 9 c = 5 c = 4 c = 3 c = 3 c = 3 c = 3 a = 87 92 97 102 107 112 117 c = 8 c = 5 c = 4 c = 3 c = 3 c = 3 a = 92 97 102 107 112 117 c = 7 c = 4 c = 3 c = 3 c = 3 a = 97 102 107 112 117 c = 6 c = 4 c = 3 c = 3 a = 102 107 112 117 c = 5 c = 3 c = 3 a = 107 112 117 c = 4 c = 3 a = 112 117 c = 3 a = 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))

``` c = 6 c = 4 c = 3 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = Columns 1 through 16 2 3 4 5 101 111 121 131 141 151 161 171 201 202 203 204 Column 17 205 c = 5 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 3 4 5 101 111 121 131 141 151 161 171 201 202 203 204 205 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 4 5 101 111 121 131 141 151 161 171 201 202 203 204 205 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 5 101 111 121 131 141 151 161 171 201 202 203 204 205 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 101 111 121 131 141 151 161 171 201 202 203 204 205 c = 9 c = 5 c = 4 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 111 121 131 141 151 161 171 201 202 203 204 205 c = 8 c = 5 c = 5 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 121 131 141 151 161 171 201 202 203 204 205 c = 7 c = 4 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 131 141 151 161 171 201 202 203 204 205 c = 6 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 141 151 161 171 201 202 203 204 205 c = 5 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 a = 151 161 171 201 202 203 204 205 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 161 171 201 202 203 204 205 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = 171 201 202 203 204 205 c = 3 c = 3 c = 3 c = 3 c = 3 a = 201 202 203 204 205 c = 6 c = 4 c = 3 c = 3 a = 202 203 204 205 c = 5 c = 3 c = 3 a = 203 204 205 c = 4 c = 3 a = 204 205 c = 3 a = 205 ```

6   Fail
%% a = [7:17:302 primes(300)]; a = sort(a); stride = 17; assert(isequal(skip_sequence_stride(a),stride))

``` c = 3 c = 3 c = 3 c = 3 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 5 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = Columns 1 through 16 3 5 7 7 11 13 17 19 23 24 29 31 37 41 41 43 Columns 17 through 32 47 53 58 59 61 67 71 73 75 79 83 89 92 97 101 103 Columns 33 through 48 107 109 109 113 126 127 131 137 139 143 149 151 157 160 163 167 Columns 49 through 64 173 177 179 181 191 193 194 197 199 211 211 223 227 228 229 233 Columns 65 through 79 239 241 245 251 257 262 263 269 271 277 279 281 283 293 296 c = 4 c = 4 c = 4 c = 4 c = 4 c = 4 c = 3 c = 4 c = 3 c = 3 c = 4 c = 4 c = 4 c = 4 c = 4 c = 3 c = 4 c = 4 c = 3 c = 3 c = 4 c = 4 c = 4 c = 3 c = 3 c = 4 c = 3 c = 4 c = 4 c = 4 c = 3 c = 4 c = 3 c = 3 c = 4 c = 3 c = 4 c = 3 c = 4 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = Columns 1 through 16 5 7 7 11 13 17 19 23 24 29 31 37 41 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 109 113 126 127 131 137 139 143 149 151 157 160 163 167 173 Columns 49 through 64 177 179 181 191 193 194 197 199 211 211 223 227 228 229 233 239 Columns 65 through 78 241 245 251 257 262 263 269 271 277 279 281 283 293 296 c = 3 c = 3 c = 6 c = 3 c = 6 c = 3 c = 5 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 6 c = 8 c = 3 c = 5 c = 3 c = 3 c = 4 c = 3 c = 3 c = 3 c = 3 c = 5 c = 4 c = 3 c = 5 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 4 c = 4 c = 3 c = 4 c = 4 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 c = 3 a = Columns 1 through 16 7 7 11 13 17 19 23 24 29 31 37 41 41 43 47 53 Columns 17 through 32 58 59 61 67 71 73 75 79 83 89 92 97 101 103 107 109 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 211 223 227 228 229 233 239 241 Columns 65 through 77 245 251 257 262 263 269 271 277 279 281 283 293 296 c = 1 c = 3 c = 4 c = 3 c = 5 c = 3 c = 19 c = 3```