If you aren't already in the know, these ten problems are from the 2008 Winter Scripting games.
For each problem, I'm going to quickly sum up the interesting (interesting TO ME) bits of each problem, then I'm going to post the full source.
This is not as straightforward as it looks. We are presented with a list of votes, each person voting for their preferred candidates, in order of preference. For each vote, you need to first count them as if there are 4 candidates, then count as if there are 3, then 2, until a candidate gets the majority vote. I'm actually proud of my solution. Some of the awesomeness is embodied in the following representative line:
$runoffCandidates = $results | Sort Percent -desc | select -first ($results.Count - 1) | % { $_.Name }
This is the magic that removes the candidate who just got booted off the island by reconstructing the list of the surviving candidates.
Remember Me
b, blockquote@cite, em, i, strike, strong, sub, sup, u
Powered by: newtelligence dasBlog 2.2.8279.16125
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, Peter Seale
E-mail