this problem is multi-valued. 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 :)
I use a cheap for the last one. Any help with the last one?
this new implicit expansion functionality is a great excuse to revisit old problems :)
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.
i have no idea what dist or dmperm are/do...
wow, very nice double arrayfun
they were once for loops
944 Solvers
1016 Solvers
We love vectorized solutions. Problem 1 : remove the row average.
610 Solvers
Integer sequence - 2 : Kolakoski sequence
125 Solvers
640 Solvers