Problem 317. Find the stride of the longest skip sequence
Solution Stats
Problem Comments

4 Comments
this problem is multivalued. it is equally valid to say that, in the case of the example, the stride associated with the longest skip sequence is 2.
Fair enough. I changed the wording to remove the ambiguity.
I added another test and rescored. It appears that DIST no longer works. The DIST function is from the Neural Networks Toolbox. It shouldn't have worked in the past, but since it did, it played a part in a lot of answers. Sorry for the discontinuity.
Tough !
Two years before understand that the sequence must contain only elements of a :)
Solution Comments

1 Comment
I use a cheap for the last one. Any help with the last one?

2 Comments

1 Comment
this new implicit expansion functionality is a great excuse to revisit old problems :)

4 Comments
what does the dist function do?
'dist' just computes the euclidean distance between two lists of vectors (the dimensionality size(dist(a,b)) is the same as size(a*b)). In this case ~dist(a',a+s) is just the same as bsxfun(@eq,a',a+s), the matrix defining a directional graph of the elements of 'a' with distance 's'.
just for completion: the matrix above is nilpotent (with degree lower than the length of the vector a), if you sum all of its powers D=sum_n{C^n} (and this is what polyvalm does) you get a matrix where d(i,j)=1 if i is connected to j in this graph; it you then take the largets column sum of the result (this is what norm(D,1) does) you get the maximum length of a sequence with stride s (across all possible starting nodes in a)...
I am impressed.

1 Comment
i have no idea what dist or dmperm are/do...

2 Comments
wow, very nice double arrayfun
they were once for loops
Problem Recent Solvers132
Suggested Problems

6506 Solvers

Longest run of consecutive numbers
3972 Solvers

Convert from Base 10 to base 5
243 Solvers

3748 Solvers

647 Solvers
More from this Author50
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!