[Community Puzzle] Who is leading ? - Puzzle discussion

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Edjy,validated by @ManuelJ,@Anoyakh and @Harry.B.
If you have any issues, feel free to ping them.

Before I started solving it, I thought about the case, what if the teams had the same time to get points, “no, that’s some kind of nonsense, that can’t happen” I decided. I wrote the wrote the solution and didn’t pass the last pretest - I already started to guess by its name why I didn’t pass it, opened it and realized that my guess was correct. Well, I corrected the solution, but the overall impression of the puzzle was already spoiled (why is this case in this puzzle - just to irritate?).
But before that, I encountered another strange behavior - in the first pretest for the second team, my time did not match, 1 minute was missing. I started to look into what was going on, but I still didn’t understand, and then I decided to do the following: my solution implies that if a team was leading at the end of the match, then add time equal to 80 - leadingSince, so I changed 80 to 81, and what did you think, the first pretest passed, like all the others, until the last one, the situation with which I wrote above. And now the question arises WHY IS THIS SO? Why if a team starts to lead from the 76th minute until the end of the match, then in total it leads for 5 minutes, and not 4? Perhaps there is an error in my calculation, but then the time of the first team in the first pretest would not have matched either, as well as the rest of the pretests/tests (of course, if they are compiled correctly).

Validators 1 and 3 fail to validate. What approach is implemented for these two tests?

There seems to be nothing special about validator 1 or 3. Validator 1 is similar to test 1 with different values and validator 3 is similar to test 2 with different values.

I’ve tried messing around with my code to recreate those tests failing but with no luck, do you want to dm me your code so I can have a look?

1 Like

My interpretation is that the minutes are 1-indexed, not 0-indexed, so “minute 1” is interval [0:00, 1:00], “minute 2” is interval [1:00, 2:00], etc., and “minute 76” is interval [75:00, 76:00]. The match lasts 80 minutes, which corresponds to interval [0:00, 80:00], so if a team starts to lead at the beginning of minute 76, then it leads for all of interval [75:00, 80:00], which is five minutes.

Well, that’s my posteriori interpretation. I also had to change an 80 with an 81 in my code to pass the tests :stuck_out_tongue:

EDIT: I just looked at the solution of the author of the puzzle. Instead of sorting the events by time, they bruteforce through all minutes from minute 1 to minute 80 (indeed 1-indexed), and for each of these minutes they search through all the score lists to find if something happened at that minute. What’s worse, their loop starts with

t = 0
while t<80:
    t += 1
    ...

which makes it slightly non-obvious that they really iterate over range(1, 81) and not range(0, 80).

All this is true, considering that such a system is for example in football, and in addition the condition said:

Consider that the points are scored at the beginning of a minute.

I realize that I overreacted.