With inspiration from Problem 56195. Possible Ruby Scores, given the final score for two teams in an American football game (score1, score2), return two matrices (team1_combs, team2_combs) representing all possible combinations of scores by each team (Official NFL Scoring Plays).
In American football, the 7 possible ways of scoring are:
- Touchdown - 6 points
- Try after touchdown - 1 point
- Try after touchdown - 2 points
- Safety - 2 points
- Field Goal - 3 points
- Defensive safety on try after touchdown (i.e. conversion safety) - 1 points
- Defensive "touchdown" on try after touchdown - 2 points
Values for score1 and score2 include all natural numbers (realistically <100), and the resulting matrices will have dimensions n1 x 7 and n2 x 7, where n1, n2 are the total number of possible scoring combinations for each team, respectively. The order of the elements in the rows for team1_combs and team2_combs should follow the above list.
*** Attention - There is added complexity in the scoring possibilities in that the number of tries after touchdowns (also known as extra points or point after attempts) must be less than or equal to number of touchdowns. This constraint is further complicated by the possibility of defensive scores on tries after touchdowns, in which the possible number of scores is constrained by the touchdowns scored by the opposing team.
Example
[t1_combs, t2_combs] = amerfootballscores(5, 8)
t1_combs =
0 0 0 0 1 0 1
0 0 0 1 1 0 0
0 0 0 2 0 1 0
t2_combs =
0 0 0 1 2 0 0
0 0 0 4 0 0 0
1 0 0 1 0 0 0
1 0 1 0 0 0 0
This system is known as a linear Diophantine equation, an equation where only the integer--and in this case only nonnegative--solutions are of interest.
Each team's score can be modeled by the following equation:
6(tds) + 1(off. 1 pt. pats) + 2(off. 2 pt. pats) + 2(safs) + 3(fgs) + 1(def. 1 pt. pats) + 2(def. 2 pt. pats) = score
>>> with the added constraints:
off. 1 pt. pats + off. 2 pt. pats <= tds
def. 1pt. pats + def. 2pt. pats <= tds for opponent
Solution Stats
Problem Comments
8 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers5
Suggested Problems
-
3732 Solvers
-
Read a column of numbers and interpolate missing data
2350 Solvers
-
240 Solvers
-
10245 Solvers
-
397 Solvers
More from this Author3
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
I'll admit I don't understand the example given. Based on the problem description, you would expect that t1_combs*s (where s = [6 3 2 1 2 1 2].') is equal to s1*ones(height(t1_combs, 1)), and dto. for t2_combs, but this isn't true for the given example (where the results are, instead, [4 3 3].' and [5 4 7 8].').
Also, the second constraint -- total number of defensive scores is bounded by the opposing team's touchdowns means that t1_combs and t2_combs cannot be considered in isolation since whether a combination for (say) team 1 is valid depends on the combination (not just score!) of team 2.
The columns in the matrix have a different order than in the problem description. From what I figured out, it should be:
1. Touchdown - 6 points
2. Try after touchdown - 1 point
3. Try after touchdown - 2 points
4. Safety - 2 points
5. Field Goal - 3 points
6. Defensive safety on try after touchdown (i.e. conversion safety) - 1 points
7. Defensive "touchdown" on try after touchdown - 2 points
Thanks, Stefan! I'll take another look keeping in mind your ordering.
Thank you so much for the edit @Stefan, my apologies on the mistake and confusion; I updated the problem statement to reflect the order you listed
My apologies @Christian for the sloppy problem writing on my part, I understand the frustration my error may have caused you
@Josh no worries, it happens.
The test suite only accepts one particular order of combinations. This disqualifies valid answers, and discourages original solutions. it could be improved by sorting the rows before comparison:
'assert(isequal([sortrows(t1_combs);sortrows(t2_combs)],[sortrows(team1);sortrows(team2)]))
@Alex thank you for the feedback, i'm all about encouraging creativity in solution methods and would like adjust the test suite to be more accommodating
i understand that your proposed solution seeks to sort the rows in each combination matrix as a means of accounting for differences in solutions' column/header arrangements, i'm not clear on how that ensures accurate solutions though because what about in cases where there are repeat values (e.g. # of tds, # of fgs, # of off./def. pats, etc.)
would it not be possible for a rows in a matrix that is incorrect to be sorted and subsequently match a solution, albeit by a chance that is somewhat rare. i might be wrong as i am not quite proficient at this stuff. would a more robust test suite ask for solutions to submit their column headers as well or to pair up the variables and their associate values in a table? maybe even ramp it up to a string/sentence describing the outcome. it seems like the latter might be overcomplicating the problem that's mean to be focused on solving a system of equations versus also testing string creation/manipluation
thank you for your help!