Problem 61064. Who Holds the Lord Ned Challenge Shield?
During the Nedball Premier League regular season, each of the n teams plays each of the other (n-1) teams twice, once at home and once away (for a total of n(n-1) matches). As well as the premiership trophy, teams also compete throughout the season for the prestigious Lord Ned Challenge Shield.
The eccentric ruler of Nedsburg, Lord Ned, donated this ornate trophy to the league, decreeing that every time the current holder played a home match, the Challenge Shield would be on the line. If the visiting team wins that match, they take the Challenge Shield and become the new holders. Their home matches now become Challenge Shield defenses, and so on.
Given a table of a season's league results and the name of the current holders of the Shield (at the start of the season), return a table documenting the holders of the Shield throughout the season.
The input table will have four variables: HomeTeam, HomeScore, AwayTeam, and AwayScore. These hold the names and scores of both teams in every league match, in order.
The output table should have three variables: Match, Team, and Defenses. Match is the number of the league match in which the Shield changed hands. Team is the name of the victorious team. And Defenses is the number of successful defenses that team managed before the next holder took it from them (or before the end of the season, in the case of the last holder in the table). The first row of the table represents the current holder at the beginning of the season; the value of Match should be 0.
Examples
The table season holds the 12 matches for a league with 4 teams:
season =
12×4 table
HomeTeam HomeScore AwayTeam AwayScore
_________ _________ _________ _________
"Vanders" 90 "Magics" 80
"Hankels" 8 "Magics" 30
"Magics" 58 "Hankels" 38
"Hankels" 56 "Vanders" 92
"Vanders" 78 "Ones" 24
"Ones" 26 "Magics" 67
"Ones" 47 "Vanders" 65
"Vanders" 79 "Hankels" 85
"Hankels" 16 "Ones" 8
"Magics" 89 "Ones" 75
"Ones" 69 "Hankels" 21
"Magics" 22 "Vanders" 54
The Vanders hold the Shield at the start of the season.
The first match of the season is a home fixture for the Vanders, and is therefore their first Shield defense. They successfully hold off the Magics 90-80 to retain the Shield. Their next home match is match 5 against the Ones, and again they are victorious (78-24). However, their tenure is ended in match 8, when they are defeated 85-79 by the Hankels. The very next match is a home match for the new holders, and they successfully defend their new title against the Ones in a low-scoring fixture (16-8). That is the last home match for the Hankels, so they end the season as the holders (even though the Ones get some measure of revenge by crushing them 69-21 in match 11, but that does not count as a Shield defense, as it is an away game for the Hankels).
champs = followtheshield(season,"Vanders")
champs =
2×3 table
Match Team Defenses
_____ _________ ________
0 "Vanders" 2
8 "Hankels" 1
A three-team league, with the Invhilbs holding the Shield at the beginning of the season:
season =
6×4 table
HomeTeam HomeScore AwayTeam AwayScore
__________ _________ __________ _________
"Magics" 5 "Compans" 50
"Invhilbs" 84 "Magics" 36
"Compans" 42 "Magics" 81
"Compans" 75 "Invhilbs" 66
"Invhilbs" 51 "Compans" 73
"Magics" 3 "Invhilbs" 34
champs = followtheshield(season,"Invhilbs")
champs =
2×3 table
Match Team Defenses
_____ __________ ________
0 "Invhilbs" 1
5 "Compans" 0
Or if the Compans held the Shield initially:
champs =
3×3 table
Match Team Defenses
_____ __________ ________
0 "Compans" 0
3 "Magics" 0
6 "Invhilbs" 0
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers46
Suggested Problems
-
Who Holds the Lord Ned Challenge Shield?
46 Solvers
More from this Author33
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!