Created
March 11, 2019 09:12
-
-
Save jdwaudby/9de46bebd7e6a9d3658039839d9ec064 to your computer and use it in GitHub Desktop.
LINQPad script for generating a randomised list of F1 drivers for a given list of players
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
var players = new List<Player> { | |
new Player(1,"Player 1"), | |
new Player(2,"Player 2"), | |
new Player(3,"Player 3"), | |
new Player(4,"Player 4"), | |
new Player(5,"Player 5"), | |
new Player(6,"Player 6"), | |
new Player(7,"Player 7"), | |
new Player(8,"Player 8"), | |
new Player(9,"Player 9"), | |
new Player(10,"Player 10"), | |
}; | |
var drivers = new List<Driver> { | |
new Driver("Sebastian Vettel", "Ferrari"), | |
new Driver("Kimi Räikkönen", "Ferrari"), | |
new Driver("Sergio Pérez", "Force India-Mercedes"), | |
new Driver("Esteban Ocon", "Force India-Mercedes"), | |
new Driver("Romain Grosjean", "Haas-Ferrari"), | |
new Driver("Kevin Magnussen", "Haas-Ferrari"), | |
new Driver("Stoffel Vandoorne", "McLaren-Renault"), | |
new Driver("Fernando Alonso", "McLaren-Renault"), | |
new Driver("Lewis Hamilton", "Mercedes"), | |
new Driver("Valtteri Bottas", "Mercedes"), | |
new Driver("Daniel Ricciardo", "Red Bull Racing-TAG Heuer"), | |
new Driver("Max Verstappen", "Red Bull Racing-TAG Heuer"), | |
new Driver("Nico Hülkenberg", "Renault"), | |
new Driver("Carlos Sainz Jr.", "Renault"), | |
new Driver("Marcus Ericsson", "Sauber-Ferrari"), | |
new Driver("Charles Leclerc", "Sauber-Ferrari"), | |
new Driver("Pierre Gasly", "Scuderia Toro Rosso-Honda"), | |
new Driver("Brendon Hartley", "Scuderia Toro Rosso-Honda"), | |
new Driver("Lance Stroll", "Williams-Mercedes"), | |
new Driver("Sergey Sirotkin", "Williams-Mercedes") | |
}; | |
Random random = new Random(); | |
var driverList = new List<Driver>(); | |
driverList.AddRange(drivers.OrderBy(x => random.Next())); | |
var playerList = new List<Player>(); | |
playerList.AddRange(players.OrderBy(x => random.Next())); | |
List<PlayerDriver> assignments = new List<PlayerDriver>(); | |
for (int i = 0; i < players.Count; i++) | |
{ | |
assignments.Add(new PlayerDriver {Player = playerList[i], Driver = driverList[i]}); | |
} | |
assignments.OrderBy(x => x.Player.Id).Select(x => new { PlayerNo = x.Player.Id, PlayerName = x.Player.Name, Driver = x.Driver.Name, Team = x.Driver.Team }).Dump(); | |
} | |
class Player | |
{ | |
public Player(int id, string name) | |
{ | |
Id = id; | |
Name = name; | |
} | |
public int Id { get; set; } | |
public string Name { get; set; } | |
} | |
class Driver | |
{ | |
public Driver(string name, string team) | |
{ | |
Name = name; | |
Team = team; | |
} | |
public string Name { get; set; } | |
public string Team { get; set; } | |
} | |
class PlayerDriver | |
{ | |
public Player Player { get; set; } | |
public Driver Driver { get; set; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment