Problem 58847. Possible American Football Scoring Combinations

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:
  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
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

83.33% Correct | 16.67% Incorrect
Last Solution submitted on Aug 28, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers5

Suggested Problems

More from this Author3

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!