Last active
May 14, 2018 13:26
-
-
Save jdwaudby/4131a23297bd608ed39f5b289d64a88e to your computer and use it in GitHub Desktop.
LINQPad script for generating a randomised list of F1 drivers for any given total
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int total = 18; | |
string[] drivers = { | |
"Sebastian Vettel, Ferrari", | |
"Kimi Räikkönen, Ferrari", | |
"Sergio Pérez, Force India-Mercedes", | |
"Esteban Ocon, Force India-Mercedes", | |
"Romain Grosjean, Haas-Ferrari", | |
"Kevin Magnussen, Haas-Ferrari", | |
"Stoffel Vandoorne, McLaren-Renault", | |
"Fernando Alonso, McLaren-Renault", | |
"Lewis Hamilton, Mercedes", | |
"Valtteri Bottas, Mercedes", | |
"Daniel Ricciardo, Red Bull Racing-TAG Heuer", | |
"Max Verstappen, Red Bull Racing-TAG Heuer", | |
"Nico Hülkenberg, Renault", | |
"Carlos Sainz Jr., Renault", | |
"Marcus Ericsson, Sauber-Ferrari", | |
"Charles Leclerc, Sauber-Ferrari", | |
"Pierre Gasly, Scuderia Toro Rosso-Honda", | |
"Brendon Hartley, Scuderia Toro Rosso-Honda", | |
"Lance Stroll, Williams-Mercedes", | |
"Sergey Sirotkin, Williams-Mercedes" | |
}; | |
Random random = new Random(); | |
int listsRequired = ((total - 1) / drivers.Length) + 1; | |
//listsRequired.Dump(); | |
var driverList = new List<string>(); | |
for (int i = 0; i < listsRequired; i++) | |
{ | |
driverList.AddRange(drivers.OrderBy(x => random.Next())); | |
} | |
//driverList.GroupBy(x => x).Select(x => new {driver = x.Key, occurrence = x.Count()}).Dump(); | |
// Final list | |
driverList.Take(total).Select((driver, i) => new { index = i + 1, driver}).Dump(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment