Break a tie in a sum of a series of points

183 Views Asked by At

I'm an engineer and a programmer, NOT a mathematician. I hope that I am able to describe my problem well enough for you to understand, even though I'm incapable of asking it in "mathematician speak".

I'm trying to find a way to programmatically break ties in points earned from finishing position in a series of races. Points are earned for each race based on finishing position. Those points are totaled up for the series of races, and the total points are ranked to determine finishing position for the series.

The problem arises when there is a tie in the total points earned. I need to break the tie based on "most first place finishes, then second place finishes, then third place finishes, etc". Here is a very simple example:

       ||     Racer A    ||     Racer B    |
| Race || Place | Points || Place | Points |
|======||=======|========||=======|========|
|   1  ||   1   |   25   ||   2   |   22   |
|------||-------|--------||-------|--------|
|   2  ||   2   |   22   ||   1   |   25   |
|------||-------|--------||-------|--------|
|   3  ||   3   |   20   ||   4   |   18   |
|------||-------|--------||-------|--------|
|   4  ||       |        ||  18   |    2   |
|======||=======|========||=======|========|
|  TOT ||       |   67   ||       |   67   |
|======||=======|========||=======|========|

As you can see, the points earned results in a tie. Racer A however needs to win the tie breaker. Both racers have one first place finish and one second place finish, but the tie is broken when Racer A has a third place finish and Racer B does not.

As a programmer I am capable of programming a "brute force" solution as simple as I have just described, but the solution will be slow. I am trying to find a solution that involves an additional calculation on the place or points where the result could be summed (or otherwise aggregated) to break the tie.

For example, if we let Points Earned be "p", then you could use 2^p as a tiebreaker column, and summing that up will break the tie (in this particular case anyway). Example:

       ||     Racer A                 ||     Racer B                 |
| Race || Place | Points | TieBreaker || Place | Points | TieBreaker |
|======||=======|========|============||=======|========|============|
|   1  ||   1   |   25   |  33554432  ||   2   |   22   |   4194304  |
|------||-------|--------|------------||-------|--------|------------|
|   2  ||   2   |   22   |   4194304  ||   1   |   25   |  33554432  |
|------||-------|--------|------------||-------|--------|------------|
|   3  ||   3   |   20   |   1048576  ||   4   |   18   |    262144  |
|------||-------|--------|------------||-------|--------|------------|
|   4  ||       |        |            ||  18   |    2   |         4  |
|======||=======|========|============||=======|========|============|
|  TOT ||       |   67   |  38797312  ||       |   67   |  38010884  |
|======||=======|========|============||=======|========|============|

This is super convenient from a programming standpoint, because the tie breaker can always be easily calculated, the total can be easily calculated, and those results can easily be sorted (as in, a query against a database).

But there are two problems with this. First, it doesn't work in all cases (it works in a lot of them, but not all). Second, if the point values given are in the thousands, then the tiebreaker number will be so huge, that it is difficult to represent in a programming language or database.

Surely there is a way to break this tie that works in all cases, and doesn't use numbers so large that they are difficult for a computer to represent. I'm all ears!

PS I don't even know what tags to use on this question. If you would like to add any appropriate tags, I would appreciate it.

EDIT:

Is there a way to figure this tie breaker based on the points earned for each race, rather than on the Place (Rank)? In other words, what if I don't know the Place the Racer finished, only the Points that they earned. You would then order by "Most 25 points earned, then by most 24 points earned, then by most 23 points earned, etc"

2

There are 2 best solutions below

8
On BEST ANSWER

If there are $k-1$ races, then set the first place to be $25 + \frac1k$ points instead of $25$, and the second place $22+\frac1{k^2}$ and so on.

That way, the total number of points is equal to the total number as per the old scoring system plus

$$\text{number of wins}\cdot \frac{1}{k^1} + \text{number of second places}\frac1{k^2} + \cdots$$

And because there are only $k-1$ races, sorting by this number should make no errors.

Note: this doesn't even require you to have two columns, you just modify the points column so that ties do not happen.

1
On

If there are a limited number of races run and significant places, then you can encode a count of each place attained in a single number.

E.g., assuming only 1st, 2nd, 3rd, 4th places are significant and each racer runs 9 or fewer races, you could encode

$\begin{array}{c|c|c|c|c}&\text{Racer A}&\text{Racer B}&\text{Racer C}&\text{Racer D}\\\hline\text{# 1st places}&1&1&2&0\\\text{# 2nd places}&2&3&1&6\\\text{# 3rd places}&1&2&3&1\\\text{# 4th places}&3&1&1&0\\\hline\text{Encoding}&1213&1321&2131&0610\end{array}$

If the number of races run is more than 9 but less than 99, then you can encode the place counts as pairs of digits:

$\begin{array}{c|c|c|c|c}&\text{Racer A}&\text{Racer B}&\text{Racer C}&\text{Racer D}\\\hline\text{# 1st places}&16&31&22&50\\\text{# 2nd places}&72&43&12&61\\\text{# 3rd places}&11&23&13&41\\\text{# 4th places}&3&1&1&0\\\hline\text{Encoding}&16721103&31432301&22121301&50614100\end{array}$

If you need to take account of even more places, or 8 digits is too big for your native integer types, then you can use formatted strings of digits provided you zero pad them appropriately.