Look at the light with distance = 13574 and duration = 5sec.
With a speed of 88 you need 3.6 * 13574 / 88 sec to reach it, which is ~555sec.
Since the light starts green and switches every 5sec, you reach it after 111 switches, which means it’s red.
I should create a bot to auto reply to this thread
Look at the light with distance = 3000 and duration = 10sec.
With a speed of 97 you need 3.6 * 3000 / 97 sec to reach it, which is ~111sec.
Since the light starts green and switches every 10 sec, you reach it after 11 switches, which means it’s red.
Yeah thanks, I guessed that the car reaches a red light, that was pretty obvious, the problem is that I can’t understand why my code is working for every other case and not for this one. Is it a particular case? Is there something special to take care of in this case?
Just have your program print any value you compute for that light, and compare them to the correct ones. That should tell you where things are going wrong, and also probably why.
Hey, I suceeded the puzzle by using a more higher floatting precision degree, but I think there’s a way to do it with only integers.
I searched 3 days, but I think I miss something. If somebody has time and the will to give me a little course, (in private ) I would appreciate to learn how to do, or at least, trying to do it with some clues
Hi,
Thanks for the Puzzle.
I have 100% at the tests in C but when I submit it… the test 2 and 3 don’t pass.
As those test are really easy compare to the few last one, I can’t figure out what is happening differently. I am a bit lost right now if you could give me a hint, it would be nice
Thanks
PS (already tried to adapt entry variables sizes and limit, setting default values…).
When I faced this puzzle I was somehow worried due to the many comments abound roundings, floats, precission, errors, etc…
But if you give it a thought it is so simple. Just need a couple of while/fors… someone called it brut force, but the speed being integer I think it sounds more than it really is. The 9th test is the longest and in Java takes less than 25 miliseconds. Maximum complexity (down to speed 1) is O(maxspeed*lights). All in all below 40 lines of code including the imports, inputs, etc and with clean “airy” code.
all of the testcases are working for me and I cant think why it wouldn’t work but when I submit, the German Highway case doesn’t work for me and I also cant see what is the input in this case and I have no idea how to fix it.
You are right, there is something to do with the number 60 but when the script calculets it it gets 59.9999999, you can cheak the rounded result along with the normal result like i did, and it fixed that isue in the tests, but when i submit it dosnt work and i have no idea why
Do traffic lights turn green at the time I get into their zone, or do they work by their durations from t=0?
Because I made a code that assumes they do their rounds from t=0 and it works only for like half of the cases, but when I changed it like they turn green when I get into their zone, the other half worked.
I finally got 100% ! The idea is while one of a light return false to the condition “it’s green”, then decrement the speed by 1. Whereas my previous code I was calculating the new speed with a array of speeds possibilities for each light.
Hello,
Can you tell me does this puzzle work for Python ? I have created a solution but it doesn’t work when it should. for the 5 test case speed 78 should be also a correct answer (i checked with calculator ) but it says that the speed should be lower. I would appriciate any response. Thank you.