Cody

# Problem 317. Find the stride of the longest skip sequence

Solution 3292058

Submitted on 20 Oct 2020 by Paul Morant
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))

l = 0 5 6 3 3 2 2 2 0 0 4 2 2 2 2 2 0 0 0 3 5 3 2 2 0 0 0 0 2 2 2 2 0 0 0 0 0 4 2 2 0 0 0 0 0 0 3 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0

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

l = 0 2 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 2 11 2 6 2 2 4 2 2 3 2 3 2 2 2 2 2 0 0 0 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 2 10 4 4 5 2 2 4 2 3 2 2 2 2 2 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 8 4 9 2 2 5 2 3 3 2 2 2 2 0 0 0 0 0 0 0 7 5 3 3 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 6 3 2 2 3 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 5 4 8 2 4 3 2 2 2 2 0 0 0 0 0 0 0 0 0 0 4 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 3 3 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 2 7 4 3 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 3 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 3 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

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

l = 0 11 6 4 3 3 2 2 2 2 2 2 2 2 0 0 10 5 4 3 3 2 2 2 2 2 2 2 0 0 0 9 5 3 3 3 2 2 2 2 2 2 0 0 0 0 8 4 3 3 3 2 2 2 2 2 0 0 0 0 0 7 3 4 3 3 2 2 2 2 0 0 0 0 0 0 7 6 3 3 3 2 2 2 0 0 0 0 0 0 0 6 3 2 2 2 2 2 0 0 0 0 0 0 0 0 5 5 3 3 2 2 0 0 0 0 0 0 0 0 0 4 2 2 2 2 0 0 0 0 0 0 0 0 0 0 3 4 2 2 0 0 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0

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

l = 0 17 9 6 5 4 3 3 3 2 2 2 2 2 2 2 2 0 0 16 8 6 4 4 3 3 2 2 2 2 2 2 2 2 0 0 0 15 8 5 4 3 3 3 2 2 2 2 2 2 2 0 0 0 0 14 7 5 4 3 3 2 2 2 2 2 2 2 0 0 0 0 0 13 7 5 4 3 3 2 2 2 2 2 2 0 0 0 0 0 0 12 6 4 3 3 2 2 2 2 2 2 0 0 0 0 0 0 0 11 6 4 3 3 2 2 2 2 2 0 0 0 0 0 0 0 0 10 5 4 3 2 2 2 2 2 0 0 0 0 0 0 0 0 0 9 5 3 3 2 2 2 2 0 0 0 0 0 0 0 0 0 0 8 4 3 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 7 4 3 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 6 3 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 5 3 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

5   Pass
a = [1:5 101:10:171 201:205]; a = a(randperm(length(a))); stride = 10; assert(isequal(skip_sequence_stride(a),stride))

l = 0 5 3 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 0 0 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 8 4 3 2 3 2 2 2 2 2 2 2 0 0 0 0 0 0 0 7 4 4 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 6 3 2 3 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 5 3 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 4 2 3 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 3 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 3 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

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

l = Columns 1 through 29 0 2 2 2 2 3 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 3 3 3 3 3 2 3 2 2 3 3 3 3 2 3 3 2 2 3 3 3 2 2 3 2 3 3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