Your goal is to find out the order of the drivers in a race (1st, 2nd, 3rd, etc) each time the start / finish line is crossed. This would allow someone to see the progression of a driver throughout the race, for example if they started in 3rd, then fell backwards to 5th halfway through the race, before moving back up to 4th and finishing there.
The only data you will have is a list of car numbers, in the order they cross the start / finish line. This will not be broken up by lap, and will not have any timestamps / any other data.
For example, in a 2 lap race with no overtaking, with a starting grid of cars 43, 60, 22
, the input to your program would be 43, 60, 22, 43, 60, 22, 43, 60, 22
.
Note that each number appears 3 times (even though there are 2 laps):
- the cars start behind the line, and cross it as the race starts and they begin their first lap
- they cross the line again at the end of the first lap
- they cross the line for a final time at the end of the second lap (which is the end of the race)
The output would therefore be something like:
Race start: 43, 60, 22
End of lap 1: 43, 60, 22
End of lap 2: 43, 60, 22
(It doesn't need to be formatted like that. Standard code golf input / output rules apply).
Some things to consider:
- a car may crash, and therefore will stop appearing in the order after some number of laps
- a car may be lapped. In this case, it may also not complete the full number of laps, as the race may end once the leader has completed their final lap
- an overtake may occur during a lap
Test Cases
[10,20,30,10,20,30,10,20,30]
[
[10,20,30],
[10,20,30],
[10,20,30]
]
[10,20,30,20,10,30,20,10]
[
[10,20,30],
[20,10,30],
[20,10]
]
[10,20,30,10,20,10,30,20,30]
[
[10,20,30],
[10,20,30],
[10,20,30]
]
[10,20,30,10,20,30,10,20,10,30,20,10,20,30]
[
[10,20,30],
[10,20,30],
[10,20,30],
[10,20,30],
[10,20]
]
[10]
[
[10]
]
[30,20,40,10,20,20,20,20,20,30,10,30,40]
[
[30,20,40,10],
[20,30,10,40],
[20,30],
[20],
[20],
[20]
]
Other notes / rules
- inputs will always contain at least 1 number (i.e.: a single car starting a 1 lap race, and crashing before finishing)
- code golf scoring
- all car numbers will be integers greater than or equal to 1
[10,20,30],[10,20,30],[10]
? (And all the others likewise modified?) \$\endgroup\$