[Community Puzzle] Van Eck's sequence

For everyone who has faced troubles passing the final testcase. Note that printing to console is pretty heavy operation (this includes debug console messages).

1 Like

Exactly, I didnā€™t pass the last with console.error but without that it passed almost instantly. I used javascript map btw.

I think this can be a very good exercices to practice in C.

Hmm, my code is probably about the same then.
But the last test still takes over 10 sec.

Iā€™m doing it in Bash. The only thing I store is the last known position of all elements, and the previous element.

Hello everyone, I have got a problem with my code : I donā€™t see how to maxsimize my code :

nb = int(input());n = int(input());ls = [];tour_final = 0
if nb < 201 and n < 1000001 :
while True and tour_final < n :
ls.append(str(nb)) #On ajoute
a = list.copy(ls);del a[-1]
if str(nb) not in a :
nb = 0
else :
t = -2
i = True
while i :
if str(ls[t]) == str(nb) :
i = False
nb = t*-1-1
t-=1
tour_final += 1
print(ls[-1])
Thankā€™s, BiMathAx

I donā€™t get the example:

Term 1: The first term is 0.
Term 2: Since we havenā€™t seen 0 before, the second term is 0.

But we have seen 0 before, namely Term 1 :face_with_raised_eyebrow:

The ā€œbeforeā€ refers to term 1: You create the first term and in the same step you check if you have already seen the created number before.

Whenever I see the handle Crypticsy, I raise the difficulty level by one in my mind.
This is so hard!

1 Like

So, I tried doing this in java and passed each case except the last one(1000000 is impossible in Java I dont know how to run that test cast fast enough). Any java users who passed this know how to complete the last topic?? Any tips or advice would be greatly appreciated

Did you take note of the ā€œMemoizationā€ tag? Also, the previous posts in this thread should also provide a significant amount of information to go on.

Did in java. Try to use HashMap. Youā€™ve no need to store all sequence in memory, only the last entry index for each value.