Random Football Picks in Groovy
The contest is simple; pick who you think is going to win in all the games. The person with the most correct picks wins. You also guess how many points the next Monday Night Football game is going to have in total so if there’s a tie, whoever is closest to that number wins.
Here’s the code for my program:
def matchups = [1 : ['Atlanta','Carolina'], 2 : ['Detroit','Minnesota'],
3 : ['Green Bay','Cincinnati'], 4 : ['Jacksonville','Arizona'],
5 : ['Kansas City','Oakland'], 6 : ['New York(NYJ)','New England'],
7 : ['Philadelphia','New Orleans'], 8 : ['Tennessee','Houston'],
9 : ['Washington','St. Louis'], 10 : ['Buffalo','Tampa Bay'],
11 : ['San Francisco','Seattle'], 12 : ['Chicago','Pittsburgh'],
13 : ['Denver','Cleveland'], 14 : ['San Diego','Baltimore'],
15 : ['Dallas','New York(NYG)'], 16 : ['Miami','Indianapolis']]
def rand = new Random(System.currentTimeMillis() + Runtime.runtime.freeMemory())
matchups.each() { key, value -> println("${value[rand.nextInt(2)]}") }
def score1 = rand.nextInt(5) * 7;
def score2 = rand.nextInt(5) * 3;
println("${score1} + ${score2} = ${score1 + score2}")
I’m a Groovy newbie, one of the reasons I wanted to use the language for this little thing, so I don’t know if this is the best way of doing this but this turned out to be pretty quick and easy. The hash/array data structure I used for the _matchups _variable makes it very easy to pick the various winners with the one-liner on 11. I went with a recommendation I found for super-extra randomness on 10 just make sure.
In the end, my random picks weren’t all that accurate. I think I had 5 right out of 16. There’s randomness for you, so unreliable. :) I also learned that when a random number generator makes your picks, you can’t take the blame for making bad picks but you also can’t take credit for the ones you got right.
Feel free to steal this code if you want to make your own picks. You have to put in all the matchups for the week but I tried to format the code so I could make the list in UltraEdit using its column-editing mode and just drop the teams in. If you have a more Groovy-ish way I could have done the matchups I’d love to hear it in the comments.