|Football announcers are always pontificating about the importance of momentum.
Of course, whenever the team that doesn't have the momentum does something
good, the explanation is that the momentum has shifted. We want to do a
study of football games to determine how big a role momentum actually plays.
We define the "m-factor" to be the number of scores that immediately follow a score by
the same team minus the number of scores that immediately follow a score by the opponent.
So if "ABBAAAAAB" were the sequence of scores in a game between teams A and B,
then the m-factor would be 5 - 3 = 2. (The 5 comes from one time that a score by B was immediately followed by another score by B and four times that a score by A was immediately followed by a score by A. Similarly, the 3 comes from the one BA and the two AB's that occur.)
But we have to be careful. A high m-factor will naturally occur if one team is
just a lot better than the other. If only one team scores, no score will follow
a score by the opponent. So to judge whether
momentum played an important role, we have to compare the m-factor for a game
to the random m-factor for the given number of scores by the two teams.
For a game with n scores, the random m-factor is defined to be the average of
the n! m-factors corresponding to the n! (not necessarily distinct) permutations of the scores. For example,
the random m-factor of the game "ABA" is the average of the 6 m-factors corresponding
to "ABA", "AAB", "BAA", "BAA", "AAB", "ABA".
Create a class NoMo that contains a method momentum that is given a String
game giving the sequence of scores
by teams A and B and that returns the m-factor for the game minus the random
m-factor for that number of scores by A and B.