41
3
Output the Nth term of the Van Eck Sequence.
Van Eck Sequence is defined as:
- Starts with 0.
- If the last term is the first occurrence of that term the next term is 0.
- If the last term has occurred previously the next term is how many steps back was the most recent occurrence.
https://www.youtube.com/watch?v=etMJxB-igrc
https://www.youtube.com/watch?v=8VrnqRU7BVU
Sequence: 0,0,1,0,2,0,2,2,1,6,0,5,0,2,...
Tests:
Input | Output
- 1 | 0
- 8 | 2
- 19 | 5
- 27 | 9
- 52 | 42
- 64 | 0
EDIT
1 indexed is preferred, 0 indexed is acceptable; that might change some of the already submitted solutions.
Just the Nth term please.
Same (except for the seeing it already posted part), it seems code golfers and numberphile watchers have a decent overlap.
9Watched the numpherphile video at work and was going to post this when I got home. Curse you for getting there first. :P – Draco18s no longer trusts SE – 2019-06-10T21:27:09.310
17Does it have to be 1-indexed, or may we use 0-indexing? – Robin Ryder – 2019-06-10T22:02:06.147
6May we return or output the infinite sequence instead? – Jo King – 2019-06-11T02:10:27.033
2... or the first
n
terms? – Shaggy – 2019-06-11T15:11:39.883@Draco18s Same, I came here to post it after seeing the Numberphile video, when I saw this. – Geza Kerecsenyi – 2019-06-11T16:52:40.820
@Draco18s The same thing happened to me. :P – VFDan – 2019-07-05T16:31:57.173