6 kyu

Van Eck's Sequence

256 of 287goldenratio161

Description:

0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5, 0, 2, 6, 5, 4, 0, 5, 3, 0, 3, …

This is the Van Eck's Sequence.

Let's go through it step by step.

Term 1: The first term is 0.
Term 2: Since we haven’t seen 0 before, the second term is 0.
Term 3: Since we have seen a 0 before, one step back, the third term is 1
Term 4: Since we haven’t seen a 1 before, the fourth term is 0
Term 5: Since we have seen a 0 before, two steps back, the fifth term is 2.

And so on...

In case you missed it, the rule here is that term n+1 is the "distance" (n - m) between term n, and the highest term m with the same value, where m < n. If there is no such m (ie. We haven't "seen" it before) then the term is 0. For example:

         -------
         V     |  We "saw" a 0 two positions earlier, so the next term is 2
0, 0, 1, 0, 2, 0, ?

Your task is to find the n_th number in Van Eck's Sequence. (1-based)

There are 200 random tests of range 100 to 1000.

Good luck!

Algorithms

More By Author:

Check out these other kata created by goldenratio161

Stats:

CreatedJul 30, 2022
PublishedJul 30, 2022
Warriors Trained845
Total Skips104
Total Code Submissions900
Total Times Completed287
Python Completions256
C Completions37
Total Stars31
% of votes with a positive feedback rating90% of 72
Total "Very Satisfied" Votes60
Total "Somewhat Satisfied" Votes9
Total "Not Satisfied" Votes3
Total Rank Assessments25
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • goldenratio161 Avatar
  • Blind4Basics Avatar
  • rowcased Avatar
  • Kacarott Avatar
Ad