ANEO Sponsored Puzzle discussion

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 !

Yes: use only integer speed (not duration). :smile:

1 Like

hmm sorry but i don’t get it.

I tried to :

  • do not make conversion to m/s in a function but i do all the maths in one step (so all variables are int before calculation)

I still get this weird “19.999996”… i guess i’m doing something wrong…
can i post my code here ?

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.

3 Likes

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.

2 Likes

I really can’t see the way you may do this? using module to keep track if it lans after ?

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.

Loved this challenge! Made me think twice. (^__^)

3 Likes

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))

1 Like

I pass all the test cases but when i submit, I got the 2nd and the 7th wrong.
And i can’t figure it out, can somone help me?

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. :sweat_smile:

Hello,

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.

I have the same issue… I found a workaround to resolve this problem but it is not considered as an optimized solution…

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 :frowning:
how are these two cases different to everything else?

2 Likes

I solved it by simply reducing the decimal places… seems like a workaround instead of a proper solution!

3 Likes

what’s a decimal place?

Any digit after the dot in a float (decimal number).

There is, use a function such as this,

bool cmpf(double A, double B, double epsilon = 0.005f) // comparing floats/doubles with
{
return (fabs(A - B) < epsilon);
}

you can choose how small epsilon is

1 Like

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