Inspired by a challenge from the OUCC 2022 Seniors competition.
Background
Two teams are playing "capture the flag". They take turns invading each other's base and capturing their opposing team's flag in the shortest amount of time. The attacking players each have one soft ball they can throw at the defenders. Teams get to reduce the time they took to capture the flag by 3 seconds for each of the defenders team that gets hit with a ball.
Your Task
Write a program that calculates which team won based on who had the smallest accumulated time.
Clarifications
- There are two teams.
- There will be an even number of rounds played.
- Both teams will attack an equal number of times but it could be in any order.
Example
Let's say we have the input [['A', 20, 0], ['A', 30, 1], ['B', 40, 6], ['B', 20, 2]]
. We go through each inner list:
['A', 20, 0]
: TheA
tells us we need to add to team A. To get the number we need to add, we usetime - 3*hits
. In this case, it is20-3*0
= 20.['A', 30, 1]
: We again need to add to team A. This time it's30-3*1
= 27. Team A is now on 47.['B', 40, 6]
: This time it's 22['B', 20, 2]
: 14. B is now at 36.
Now we get the team with the lower score, in this case B, and output.
Test cases
Input -> Output
[['A', 100, 5], ['B', 95, 2]] -> A
[['A', 20, 0], ['A', 30, 1], ['B', 40, 6], ['B', 20, 2]] -> B
['A', 50, 3], ['A', 70, 5], ['B', 35, 0], ['A', 25, 1], ['B', 60, 2], ['B', 40, 4] -> B
[] -> Draw
Input / Output formats
You must take an arbitrary even number of inputs (these can all be in a list, or taken separately).
Each input must be a list of three items (in whatever order you prefer):
- The team. You must choose two distinct values for this, e.g.
0
and1
,'A'
and'B'
, etc. - The time taken for the team to get the flag (a positive integer of seconds)
- The number of hits they got (a positive integer)
Note: The number of hits will never exceed the time taken / 5, so the score will never be negative.
- The team. You must choose two distinct values for this, e.g.
You must have three distinct output possibilities:
- One for the first team winning
- One for the second team winning
- One for a draw
This is code-golf, so shortest answer in bytes wins!