mardi 15 novembre 2016

How to create an even distribution over multiple sets?

This is for a hobby project and will be implemented with Python, but this is not really important. I'm mostly looking for a good algorithm.

I want to host a racing event with more than one driver (num_drivers). The event has more than one races (num_races), and I want each driver to have a fair chance according to their position at the start using somewhat random positioning. The problem is, which starting positions do I assign to each driver for each race?

An example: for an event with num_races=3 and num_drivers=4 (named "A" to "D") a pretty good setup would be

Race 1: A B C D
Race 2: C D B A
Race 3: D B A C

The pole position would have a value of 1, the second position 2, and so on. So this setup gives quite equal values to each driver:

A: 1+4+3 = 8
B: 2+3+2 = 7
C: 3+1+4 = 8
D: 4+2+1 = 7

In the end the sum of positions of each driver should ideally be the same as for every other driver. What would be a good generic algorithm (in pseudo code) for my problem when the number of drivers and number of races can vary? Is there even already an algorithm somewhere to look at?




Aucun commentaire:

Enregistrer un commentaire