ANEO Sponsored Puzzle discussion

I was talking about “the poorly worded question”.
So yes there’s people who have problems with this puzzle, like on any other puzzle. And yes, there’s a dedicated thread to speak about that, like on any other puzzle. But you’re alone saying that the puzzle work differently of what is stated.
I taken back the puzzle, and modified my code to work like you said, with all the lights turning green when entering a new road section. My code passed 4/10 tests, and 3/10 validators.
But I have a doubt. “Each new road sets the next light to green and starts the timer for switching.” What are you calling “new road” ?

got stuck with rounding issues, moved the speed conversion to be with another calculation and everything worked out

if you test when lights are red, you can do a precious optimization avoiding to test all lights

Bonjour à Tous, je viens de finir mon code mais les tests 5,6,7,8,9 et 10 ne fonctionne pas. J’ai beau mieux regarder et tester je ne vois pas où est l’erreur. Est-ce que quelqu’un peut m’aider ? Merci
Hello everyone, I go to finish my code but the test 5,6,7,8,9 and 10 aren’t good. I try to find my mistake but I don’t find where it is… Someone can help me ? Thank’s

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

speed = int(input())
#speed conversion en m/s
d = []
tf = []
light_count = int(input())
for i in range(light_count):
    d1, tf1 = [int(j) for j in input().split()]
    d.append(d1)
    tf.append(tf1)
#print(d)
#print(tf) # temps entre chaque changement de couleur
distance_depuis_debut = 0
#création d'une iste avec les distance
df = []
for distance in d :
    distance_depuis_debut += int(distance)
    df.append(distance_depuis_debut)
#print(df)
v = speed 
sortie = 0
for i in range(speed) :
    #convertion en metre seconde :
    ms = int(v) / 3.6
    #Calcule du temps qu'il faut pour lchaque distence :
    distance_t = [] #temps qu'il faut pour arriver a la distance
    for i in df :    
        result = i / ms
        distance_t.append(result)
    #print(distance_t)
    p = 0
    Feuok = 0 #reste sur 0 si c'est bon 
    for temps in tf :
        déplacement = distance_t[p]
        couleur = déplacement / temps
        nbt = math.floor(int(couleur))
        c = 0
        for dsd in range(nbt) :
            if c == 0 :
                c = 1
            else :
                c = 0
        if c == 1 :
            Feuok = 1
        p = p + 1
    if Feuok == 0 and sortie == 0 :
        print(str(v))
        sortie = 1
    """
    if Feuok == 1 :
        print('A une vitesse de ' + str(v) + ' le feu est au rouge')
    else :
        print('A une vitesse de ' + str(v) + ' le feu est au VERT')
    """
    
    v = v - 1

Ps : don’t see the french mistake PL

For test case 5, Unsettled country road, 78km/h works for my program but it fails the test case which is telling me it expects 67Km/h. I’ve worked it out by hand and 78km/h is fine, so I think your algorithm is wrong!

max_speed [90]

light_count [3]

i [0], distance [300], duration [30]

i [1], distance [1500], duration [20]

i [2], distance [3000], duration [10]

At 78 km/h :
Cross first traffic light after 13.846154s, it’s green
Cross second traffic light after 83.076923s, it’s green
Cross third traffic light after 221.538461s, it’s green

78 km/h = 21.6666666 m/s
Total length is 4800m, so time is 4800 / 21.66666666 = 221.538461s

I rest my case, but I can always be wrong.

I think there is a problem with the test cases. I’ve submitted my own answer for this (needs cleanup!), not quite sure how you get to see it, but for instance I think the answer for test case 5 should be 78km/h. What do you get?

You’re wrong. The problem is that you are working with rounded values. So yes 78km/h pass the test approximately, but not with exact values.

Really? Ok I’ll try again!

But calculating by hand I am using more or less exact values, how many decimal points do you have to round to?

You don’t have to round anything, technically this puzzle can be solved with integers… People who solved it with floating point numbers probably just found the good combination of round, with the good precision, etc…

Er, ok, but I think I came up with a correct solution.

I agree with you, 78km/h is correct. Seems like people are arguing with this because you didn’t use integer arithmetic which seems to come up with the wrong answer.

No it’s not. I have not checked your calculus, but if you look the post just above the one you answered to, you will see why you are wrong…
By the way there’s only one correct answer to each test, which was calculated with a correct algorithm, fulfilling all the statement requirements. So no, we are not arguing 78 is false because you found it with floating point numbers, we are arguing that 78 is false because it’s not the waited answer. :roll_eyes:

Ok, but I’m arguing that 78 is correct because it works. So the expected answer should be 78. I’m not sure if you can really argue with that. However, I would like to see the code that comes up with 67, do you know where I can see that?

I can argue that you have not read the post I pointed. So I will post you a quote from the statement instead: “An integer distance representing the distance of the traffic light from the starting point (in meters).”. You are using distances like if they are between the lights, while they are from the start.

Look at the light with distance = 1500 and duration = 20sec.
With a speed of 74 you need 3.6 * 1500 / 74 sec to reach it, which is ~69sec.
Since the light starts green and switches every 20sec, you reach it when it’s red.

Ah, well now you put it like that, I can see what the problem is. In my reading of the question, the distance is 1800m, not 1500m.

If that is the case the the question is just really badly worded.

What is badly worded ? It is explicitly wrote that distances are from the starting point…

Continuing the discussion from ANEO Sponsored Puzzle discussion:

I am confused why in the last test a velocity of 74 km/h is expected. When driving with 88 km/h you exactly arrive to all lights when they switch green. Should there bee a little non zero time between green flick and driving over it?

example: Car speed is 100m/s light is 1000m away and flips every 10s then you shouldn’t be allowed because it just flicks read when you arrive. Should you then drive 50m/s or a little bit less?

In other words are the red green intervals:
green: [0,t) ; [2t, 3t) ; … - red: [t,2t) ; [3t,4t) …
or green: (0,t] ; (2t, 3t] ; … - red: (t,2t] ; (3t,4t] …
or green: (0,t) ; (2t, 3t) ; … - red: [t,2t] ; [3t,4t] …
or green: [0,t] ; [2t, 3t] ; … - red: (t,2t) ; (3t,4t) …

I belived the first one to be correct if this is the case why is 88km/h not the correct solution in the last example?