Friday, 7 May 2010

Guessing the Election

For those who read this blog from the UK you may know there was a general election yesterday.  Having stayed up all night watching  BBC1 (while nodding off regularly) it was seeming like they were taking wild guesses about who would win the seats before they were announced.

After playing Rock Paper Scissors with the computer for a bit (Code below) I thought I could probably use powershell to guess at the election.  Firstly I will show you Rock, Paper, Scissors.

get-random “Rock”,”Paper”,”Scissors”

After that I thought to the election and how it would be useful for whose who didn’t know which way to vote

get-random “labour”,”Lib Dem”,”Conservitives”,”other”

And then I thought to how to predict the election results.  For this we are going for more than a one liner although it could be done in one line.  For this I have created a folder in the root of C: called election and made a list of constituenies in a csv file and a file with a list of parties

$Locations=import-csv C:\Election\Constituenies.csv
foreach ($Location in $Locations) {write-output $Location,(Get-Random(get-content C:\Election\Parties.csv))}

This is only a basic script at the moment but it is something that could be built on to to make it more use.