Problem 44321. Van Eck's Sequence's nth member
Solution Stats
Problem Comments
-
1 Comment
interesting
Solution Comments
-
2 Comments
I don't understand why in my Matlab software it works for all the x while here it falis for x>=11
function result = VanEcksSequence(n)
A=0;
for i=1:n
if i==1
A(i+1)=0;
else
[C Chigh]=ismember(A(i),A(1:i-1));
if not(Chigh==0)
A(i+1)=i-Chigh;
else
A(i+1) = 0;
end
end
end
result = A(n);
end
@Simone Sabbatini
i dont think ur algorithm is correct. understand the sequence well..
The first term is zero. Then-
If the last term is *new* to the sequence so far then-- The next term is zero.
Otherwise:
The next term is "how far back" this last term occured previousely.
-
1 Comment
Quite an innovative way lol
Problem Recent Solvers305
Suggested Problems
-
Find the sum of all the numbers of the input vector
38164 Solvers
-
Remove all the words that end with "ain"
1651 Solvers
-
Make a random, non-repeating vector.
5369 Solvers
-
758 Solvers
-
Solve a System of Linear Equations
7087 Solvers
More from this Author76
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!