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

1 Like

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.

I had the same problem, I had to adjust the length of the game to 81 minutes to pass validators. IMO, its quite misleading to assume that an 80 minute game clock starts at 01:00 and ends at 81:00 rather than beginning at 00:00 and ending at 80:00.

Here the reason is that a goal scored at 0 (10/20/45) seconds will be counted as a goal scored in the first minute, and it turns out that, for example, in a situation where a goal is scored at 59 seconds by the first team (it will be counted as a goal in the first minute), and the second team scores a goal at 1 minute 1 second (it will be counted as a goal in the second minute), and according to the logic of the task it turns out that the first team led for 2 minutes, although in reality it turns out to be 2 seconds - counterintuitive.

P.S. the match starts at 0:00 and ends at 80:00, but since the intervals when goals are scored work as described by me and @Stef_3 above, it turns out that either you need to add 1 to the final time or subtract 1 from the initial one, and nevertheless for some reason it is enough to add 1 at the very end, and not when calculating each interval (I don’t have the strength to think why this is so).

Just another task where they didn’t take the time to check the integrity of the task logic.

Hi everyone. As explained by @Stef_3, minutes are 1-indexed. This is because in sport 1’ usually means “the first minute”, which is from 00:01 to 01:00, therefore creating a gap between the mm:ss timestamp (showing mm as 00) and the minute number (1’).
I understand it can be confusing, especially because it’s not really detailed in the statement. I chose not to dive in too much detail because one should not have to handle precision under the minute. If a team gets the lead at 4’, and loses it at 11’, it will have led during 11-4 = 7 minutes, even if it’s actually from 3:01 to 10:00.
In addition to that, the fact that points scored at the beginning of a minute means that it is not close to the intuitively corresponding timestamp (3:01 for points scored at 4’). And a team leading from 76’ (75:01) to the end will have the lead for 5 minutes (76’, 77’, 78’, 79’ and 80’), in the interval [75:01, 80:00]. The easiest way to tackle that imo is to consider that the game goes from 1:00 to 80:59, so that points scored at the beginning of the n-th minute (n’) are scored at n:01 and not n-1:01.

1 Like