ANEO Sponsored Puzzle discussion

They just say that your solution fail on some tests. Unfortunately (or luckly) you can not see the control tests. Look closely on your solution for any caveats.

But the thing is it is passing on the same tests in the IDE and fails when I submit the solution.
This happens with ā€œCountry road with no median stripā€ and ā€œGerman Highwayā€ tests. :frowning:

Thanks, it works

Hello,

Iā€™ve passed all the test cases but when I submit, I got the 2nd wrong ā€œLe feu du village 2ā€ and I wonder why:
Test Cases = 100% || Validator Cases = 90%

To avoid rounding error, I donā€™t use float and only use integer. I save fractional value with two integers.
So, I can easily compare two numbers by using this trick:
cmp(a/b, c/d) == cmp(ad, cb).

At the beginning I was using i32 and after i64 and after i128 and Iā€™m still stuck with the second validator.

Iā€™m quite sure I have no precision issue. My speed unit is km/h. Can I have an hint with for instance a new pattern reproducing the error I have in the ā€œLe feu du village 2ā€ validator case?

I wrote the code in a lot of different ways because of the German highway validation.

If you are coding in C++ use float instead of doubles! It solved my problems =)

1 Like

I am able to solve all the cases except case number 7: German Highway. I have been trying to figure it out for a long time now but couldnā€™t find what I am doing wrong. Can anyone give me some tip please? BTW I am using C++.

Hi. I have been stuck on this same puzzle for a while now. I am coding in Java and feel it must be a precision problem. When I am able to fix this test then the test 09 fails. Were you able to resolve?

I am stuck!!! I must have been trying to determine the specific issue with test 06. I would really appreciate your help by getting the validator.

Hi!
I solved all test cases , but when i submit the puzzle, the validator says the 07 - german highway test case failed. My code is not a hard coding solution. C++

it is not clear if those intervals are strict or not :
(n-1)*duration <= green_time <= n*duration

Some languages, such as Javascript have difficulty in calculating floating point numbers. The reason is that there is no specific way to prevent a number variable from becoming floating point when needed. (var is for both integers AND floating, unlike C++ for example) . So, at some point during the calculations at these two specific examples, there is a 3.9999999999996 instead of 4. So, you get the wrong result when you round down to see until the next light is red. The way I found to solve this, is when the result and the result rounded up, are more then 0.0000001 in difference, just add the difference and you are done. Rounding down causes no problems, as every number is rounded down to check if it is in the limits of being green or red, so I never bothered with it.

1 Like

Hello everyone,

Iā€™ve tried the same code in Java and Python and I pass all the test cases.

But each time I submit my code, it doesnā€™t pass validator cases 6, 7 and 10.

I think itā€™s a precision issue because when I solve the challenge with a sheet and a pen I round my results and it works so I tried to write the way I think in the IDE and Iā€™m almost sure I have the good way of thinking because all test cases in green reassures me but I donā€™t understand why all the validator cases arenā€™t validate by my code.

I read some of replies in this topic but I donā€™t find a tip that can help me.

Do you have any idea to help me to pass the last final test cases please ?

Thank you

PS : Iā€™ve tried a tip that said to reduce number of decimals but it didnā€™t work for me :frowning:

Solved : Thanks a lot to some people who really well explained a common issue with the last test case. Thanks to their comments, Iā€™ve finally properly solved the last test case and was able to reach 100% on validator cases ! :partying_face:

I have some hard code, but i dont know why

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

const int TAM = 10000;

struct light{
    double distance;
    double duration;
};

int Speed(double speed, int lightCount, light lights[TAM]);
int main()
{
    double speed;
    cin >> speed; cin.ignore();
    int lightCount;
    cin >> lightCount; cin.ignore();
    light lights[TAM];
    for (int i = 0; i < lightCount; i++) {
        cin >> lights[i].distance >> lights[i].duration; cin.ignore();
    }
    double max_speed = Speed(speed,lightCount,lights);
}

int Speed(double speed, int lightCount, light lights[TAM]){
    for(int i=speed; i>0; i--){
        bool valido = true;
        for(int j=0; j<lightCount && valido; j++){
            int tiempo_llegar=(int)(lights[j].distance/(i/3.6)+0.5); //El 0.5 es para redondear
            int coef=tiempo_llegar/lights[j].duration;   //if coef is even --> green
            if(coef%2!=0)
                valid=false;
        }
        if(valido)
            return(i);
    }

}

Whatā€™s that ?

Hi all,

I successfully passed all the tests but when I submit it, it fails on test 2,3 & 7.
Looks very weird as these are far from being the most tricky ones ā€¦

How could I debug without any clue about why it fails ?

Thank you in advance.

it was bad formatting due to #
Edited that.

1 Like

A lot of difficulties about this puzzle come from floating point and round problems. For example, do you use ceil() or floor() functions that could pass all the tests because giving the same result as a round() ?

1 Like

Donā€™t know whatā€™s your exact problem, but you have a typo in your ā€œSpeedā€ function, in the second for loop you wrote ā€œvalidoā€ instead of ā€œvalidā€. Otherwise, you donā€™t output anythingā€¦

1 Like

Thank you for your answer.

I donā€™t use round as in my algorithm I have to control what rounding I apply.
Therefore, I only use ceil and floor.

In conding game, if I understand well, the floats are limited to 15 digits :
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)

=> Iā€™ll try to change all the floats by Decimals to better control the precision. Iā€™ll let know if it changed anything.

ok ā€¦ It actually looks like a precision issue.

I transformed parameters in decimals.

1/ with getcontext().prec = 16, I have the exact same results (100% of tests cases, 70% of submission cases).

2/ Increasing this value to 32, it fails for test case 3 (ā€œroute de campagne tranquilleā€, it founds 45 instead of 90), but I pass the other 90% and I also pass 80% of submission cases.

I continue my investigation on this direction.

Honestly, I insist 'cause I donā€™t like to let problems unresolved, but I find it an upleasant exercice :unamused: