How to Solve Van Eck's Sequence in Python
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 had 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 had seen a 0 before, two steps back, the fifth term is 2. And so on…
Your task is to find the n_th number in Van Eck’s Sequence. (1-based)
The Solution in Python
Option 1
Option 2
Option 3
Test cases to validate the solution
|
|