Archery set match
MediumOnline Assessment
Score a head-to-head recurve archery match played under the set system.
Two archers, A and B, shoot sets. In each set every archer shoots an end of 3 arrows. An arrow is recorded as "X" (inner ten, worth 10), "10", "9", ..., "1", or "M" (a miss, worth 0).
- An archer's set total is the sum of the arrows in the end, with one correction: if more than 3 arrows were shot in the end, only the 3 lowest-valued arrows count (the extra, highest arrows are void). If fewer than 3 arrows were shot, the missing arrows are worth 0.
- The archer with the higher set total wins the set and gets 2 set points; if the totals are equal, each archer gets 1 set point; the loser of a set gets 0.
- Sets are played in order, at most 5. The match ends the moment an archer has 6 or more set points; that archer wins, and any later sets in the data are ignored.
- If five sets have been played and nobody has 6 points, the score is 5-5 and the match goes to a shoot-off. A shoot-off round is one arrow each, recorded as
[a_arrow, b_arrow, a_mm, b_mm], where the last two numbers are the distances in millimetres from the centre. In a round, the archer with the higher arrow value wins; if the values are equal, the archer who is closer to the centre (smaller distance) wins; if the distances are also equal, the round is void and the next round in the list is used. The first decisive round decides the match. - If the match cannot be decided from the data (fewer than 5 sets and nobody reached 6, or a shoot-off is needed but no round is decisive), there is no winner.
Input: archer_a and archer_b, lists of ends (each end a list of arrow strings, possibly empty or longer than 3), where entry k of both lists is set k + 1; both lists have the same length. shootoff, a list of shoot-off rounds (possibly empty). Shoot-off rounds are only used when the match is at 5-5 after five sets.
Output: [winner, a_points, b_points] where winner is "A", "B" or "NONE", and the points are the set points at the moment the match ended (or after all given sets, up to five, when there is no set-based winner). A shoot-off does not change the set points.
Example 1
- Input:
- [[["10","9","9"],["9","9","9"],["8","8","9"],["X","9","9"],["8","8","8"]],[["9","9","9"],["10","9","8"],["10","10","9"],["9","9","9"],["9","8","7"]],[]]
- Output:
- ["A",6,4]
- Explanation
- Set 1: A scores 10+9+9 = 28 against 27, so A leads 2-0. Set 2: 27 against 27 (10+9+8) is a tie, 1 point each: 3-1. Set 3: B scores 29 against 25: 3-3. Set 4: A scores 28 (the X counts 10) against 27: 5-3. Set 5: 24 against 24 is a tie, so A gets the 6th point and wins 6-4 without a shoot-off.
Example 2
- Input:
- [[["9","9","9"],["8","8"],["7","7","6"],["8","8","8"],["10","10","9"]],[["10","9","8","7"],["6","5","5"],["7","7","7"],["9","8","8"],["9","9","9"]],[["9","9",12,8]]]
- Output:
- ["B",5,5]
- Explanation
- Set 1: B shot four arrows, so only the three lowest (7, 8, 9 = 24) count; A scores 27, so 2-0. Set 2: A shot only two arrows (16) and B scores 16: tie, 3-1. Set 3: B wins 21-20: 3-3. Set 4: B wins 25-24: 3-5. Set 5: A wins 29-27: 5-5. The only shoot-off round has equal arrows (9 and 9), so the closer arrow decides: B at 8 mm beats A at 12 mm.
Example 3
- Input:
- [[["9","9","9"],["7","7","7"],["X","X","9"],["8","8","8"],["9","9","9"],["10","10","10"]],[["8","8","8"],["9","9","9"],["10","9","9"],["9","8","8"],["X","9","8"],["1","1","1"]],[["9","9",10,10],["10","9",7,2]]]
- Output:
- ["A",5,5]
- Explanation
- The sets go A, B, A, B and a tie in set 5 (27-27), so the score is 5-5; the sixth set listed is never played. In the shoot-off the first round (same arrow, same distance) is void. In the second round A's 10 beats B's 9, and the distances do not matter once the arrows differ, so A wins.
Constraints
0 <= len(archer_a) == len(archer_b) <= 8sets- each end has between
0and6arrows, each one of"X","10"to"1", or"M" 0 <= len(shootoff) <= 4; shoot-off distances are integers between0and100