Hey guys !
I did this training but i did a weird thing to succeed :
“if round(time_to_dist) - time_to_dist < 0.00001:
return round(time_to_dist)
return time_to_dist”
because there were weird values like “19.99999996”
i’m wondering if there is a better way to get rid of this ?
thanks !
To those having problems with floating point/rounding errors :
It is interesting to note that this problem can be solved without any floating point calculations.
It requests the integer value to pass by all lights when they are turned green. Try checking whether 88 or 89 instead of 88.848 gives you a red light somewhere.
I could think of a solution to solve it forcing every case from 1 to the lower speed limit, someone found a way to calculate the speed without brute force?
I think the purpose of this test is to check whether you know a language well enough to recognize its weaknesses and compensate for them. I love Javascript, but it is notorious for its quirks.
In this case, the problem is floating points always lose precision and become nondeterministic, especially when dealing with conversions, which can only be deterministic by using protected fractions. Since you can’t access external libraries for this problem, you have to overcome the precision issue a different way.
I can’t get the inputs to work on the ANEO challenge
The German Highway rain of traffic lights and light string all time out before the input is complete but works perfectly fine with the other challenges.
I have added the light info to collect he data and the print(len(lightinfo)) is so that I can check if the data is finished but on the 3 tasks mentioned before there is no output on all of the others it is fine. can anyone solve this for me?
speed = int(input())
light_count = int(input())
lightinfo=[]
for i in range(light_count):
distance, duration = [int(j) for j in input().split()]
lightinfo.append([distance,duration])
print(len(lightinfo))
I don’t have hardcoded solution and I pass all given the tests, and I cant get 100% I don’t know why. Any ideas? Solutions can be only integers? (Java)
Great test by the way. I have problem at first that I did not realize the lamp can be only green and red, and not green, yellow and red.
I also pass all test cases.
On Submit my code fails only at the 2nd validator…
Anybody an idea why? Can anybody help me and point me in the right direction?
Thanks!
After I figured out my solution the main issue I ran into was trouble with floating point math. xx.666666… rounding to xx.66668 then the next division giving xx.99999999 so then %2 is not == 0.
Wasn’t sure whether using the decimal module in python was accepted (and had no experience using that module) so I found that changing order of operations and using *10/36 instead of *1000/3600 fixed the issue.
Test Cases = 100% || Validator Cases = 80%
– [06] Country road with no median strip
– [07] German Highway
these two keep failing… I hate when this happens because I can never determine the reason for it failing
how are these two cases different to everything else?
I… havent stored it in m/s but calculated with it in m/s… just needed floor function and get the right interval when deciding if there is a green or red