ANEO Sponsored Puzzle discussion

I find already my way and solve it :stuck_out_tongue:


Good puzzle, but i think, this should be mentioned in puzzle , during specific second when light switches from red to green, your vehicle is allowed to move, but when light switches from green to red your vehicle can’t move ahead…
e.g suppose lightDuration is 10 seconds…
so at 10th second, light switches from green to red, so vehicle can’t move ahead,
but at 20th second, light switches from red to green, so your vehicle can move ahead…

sorry, for my bad english…

Hi. In test case number 5, my program gets 79 km/h or 21.8 m/s. why is this the wrong answer?

first light: 300m 30s: 300 / 21.8 = 14s
second light: 1500m 20s: (1500 + 300) / 21.8 = 83s. green light in the following intervals:
0-19, 40-59, 80-99.
third light: 3000m 10s: (3000 + 1500 + 300) / 21.8 = 220s. green light in the following intervals:
0-9, 20-29, 40-49, 60-69, 80-89, 100-109, 120-129, 140-149, 160-169, 180-189, 200-209, 220-229

Fun puzzle!

How are you doing that? I have ugly 1e-5 error comparison.

Hello there,
I did this test in PhP, and I run into some problem when trying my modulo ^^’
German traffic don’t pass ( i’m supposed to find 60 when I have 20 on max speed), but it’s due to my code giving me (60/15) % 2 =1 ! 4%2 should give me 0, damn it…
I also tried bit wise, ($tmpModulo&1)===0, but I have the same problem.

I’m honestly lost as to why this doesn’t work… Also tried intdiv, fmod functions too, by the way…
Thank you kindly to anyone understanding my mistake ^^"


Don’t use float, you doesn’t need them :wink:

At 60s, the second light turns red :
[0, 20[ green
[20, 40[ red
[40, 60[ green
[60, 80[ red


Its a great puzzle but when using java to solve it all solutions are oke(did not cheat)
but after submit there are 2 errors.
That is no nice.
And blocks working in the next puzzle

Which tests are blocking when you submit your solution ?

1 Like


Country road with no median strip


German Highway

Test 6 I don’t see what use case of the algorithm is needed

test 7 I can deduce the use case tested. I guess it validates that your algorithm doesn’t do unneeded tests.

So do you make calculations for every traffic lights ? If your answer is yes, you can do some optimizations.

There are no errors during user initiated testcases but only when I commit.
These tests are to “punisch” cheaters with hardcoded solutions.
That is not what I do.
I try to write easy readable solutions using Java coding possiblilties and not some mathematical trick.

I just drive at topspeed until a traffic ligt stops me.
then 1 km/hour slower until i get all greens.

That’s exactly my approach in a very naive way and all is okay. I don’t use Java but it is quite efficient, so it shouldn’t be a problem. I use a single link list in my case. Could it be a hidden complexity with the collection kind used?

I used C++ and my solution couldn’t get past German Highway when using double but passed all tests when I used float. I changed nothing else.

in my case only integers

I am having trouble with the 5. test case: Unsettled country road.

The expected answer is 67, but at this speed light 1 (distance: 1500 m, duration: 20 s) is red.

We can travel 1500 m at a speed of 67 km/h (18.611111 m/s) in just over 80 seconds (80.5970 s) and since the light switches to red at 80, this answer is wrong.

Can anyone help?

I’m sorry to say that this was pleasant at first and finally one of the worst coding game experiment I had. Must go through this discussion to see that this is a “round” problem to finally discover that in fact it’s also a matter of 32 or 64bit calculation (js friends try yo take a look at MAth.fround). Really this remove all the pleasure of getting the answer right at first. The excuse that this is to make you think doesn’t seems fair to me. I finally got it 100% in a reasonable time but get really disapointed in the end as it was not part of the explained exercise to gess that kind of detail. The based idea of the test was great btw

I think there is a confusion here an example of light chronology with a Frequency of 20 :

| -------------------- Green
|---------------------- Red
| --------------------- Green
| ----------------------- Red
| ------------------------ Green

So with this speed you are crossing it with a green light

I think this round stuff problems isn’t part of the problem. The problem is simple enough to avoid using float. If the language doesn’t provide a divide operator with integers, you can truncate the decimals.
About the 32 bits and 64 bits I don’t know, I’m quite surprised, I’m in a 63 bits integer language so perhaps that’s why I didn’t hit a problem with a 32 bits out of range limits, but I’m quite surprised, numbers aren’t so high in this puzzle.