Last active
August 29, 2015 14:05
-
-
Save selenium34/1a44ff91595996207e7e to your computer and use it in GitHub Desktop.
Fantasy Football Draft Order
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
@Grab(group='commons-cli', module='commons-cli', version='1.1') | |
class DraftOrder { | |
static main(args) { | |
def cli = new CliBuilder(header: '\nAvailable options (use -h for help):\n') | |
cli.with { | |
h(longOpt: 'help', 'Usage Information', required: false) | |
t(longOpt: 'teams', "File which contains the team names", args: 1, required: true) | |
s(longOpt: 'seeds', 'File which contains the a list of random prime numbers used for randomization', args: 1, required: false) | |
} | |
//These are simply prime numbers which were randomly selected out of | |
//the first million prime numbers, this helps ensure the random generator | |
//acts a bit more randomly. 20 numbers were chosen, as that represents the | |
//number of players on a team | |
def defaultSeeds = [66749, 303917, 1206479, 2848493, 3950599, | |
4448099, 5903789, 7157273, 8853661, 9068069, | |
10462607, 11435833, 12085699, 12956927, 13504571, | |
13833433, 14162821, 14381797, 15373511, 15485581] | |
def randomSeeds = defaultSeeds | |
def teams = [] | |
def opt = cli.parse(args) | |
cli.parse(args) | |
def teamFileName = opt.t ?: opt.teams | |
def teamData = new File(teamFileName).text | |
teamData.eachLine { teams << it } | |
def seedsFileName = opt.s ?: opt.seeds | |
if (seedsFileName) { | |
def seedsData = new File(seedsFileName).text | |
randomSeeds.clear() | |
seedsData.eachLine { | |
randomSeeds << (it as int) | |
} | |
} | |
def results = teams.collectEntries { [it, 0] } //Everyone starts with 0 points | |
randomSeeds.eachWithIndex { randomSeed, roundNumber -> | |
//Randomly sort the team names with the random prime number | |
//The random order is then randomly shuffled each round. | |
Collections.shuffle(teams, new Random(randomSeed)) | |
println "Random Team Order for Round ${roundNumber + 1}\n${teams}" | |
//Iterate over the list, and add the total to the user's current score -- adding one, as the counter starts at 0 | |
teams.eachWithIndex { teamName, index -> | |
results[teamName] = results[teamName] + index + 1 | |
} | |
} | |
println "\n\nFinal Results. Lowest point total receives first pick:\n ${results.entrySet().sort{it.value}}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment