I'm trying to do a problem but I'm stuck
How do you determine the number of ties that occurred given the number of teams in a competition, the number of games played, and the score each team has after that number of games. A victory is worth 3 points, a tie worth 1 point and a loss no points.
An example with 3 teams after 3 games:
Team A has 5 points, Team B has 1, Team C has 1.
A must've played 3 games, winning 1 and drawing 2 (once against B, once against C)
One of B of C has played 2 games (both against A!), and the other only 1.
The schedule-maker for that league should be shot
Name:
Anonymous2010-10-21 6:02
>>1
score = (1 + 1) * nties + (3 + 0) * (ngames - nties)
nties = 3 * ngames - score
I leave calculating 3 * 3 - 7 as an exercise for the reader.
[b][u]FIFTH GRADE QUALITY PROBLEM[/b][/u]. The interesting question is: do five graders now hang out on /prog/, or have the US education system gave up completely?
Name:
Anonymous2010-10-21 6:27
I suggest an exhaustive search algorithm.
For a given number of games, assume zero ties and iterate attempting one more tie until the solution is found.
On each iteration, for each team, assume their score is completely the result of ties. Check all teams. If you run out of ties, start assuming the first team that has three or more points got a victory. Check again. If it doesn't match, increase the number of victories until possible. Then start doing the same with the second team that has three or more points, but this time test all possibilities of the first team while checking every possibility of this second team. Do this until you run out of teams (if you're doing it correctly, every time you check a new team the number of possibilities to check should have grown exponentially).
Once you rule out an hypothesis, it's time for the outer iteration outlined in paragraph two. This is sure to find the solution. If you suspect there might be no solution, check that the number of ties doesn't exceed the number of games.