Created
May 6, 2014 15:31
-
-
Save michaelxor/1a5d1252425f7eea8cb5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import random | |
def tally(votes): | |
max_score = 0 | |
max_ppv = 0 | |
winner = '' | |
for book, v in votes.items(): | |
score = sum([x*(v.index(x)+1) for x in v]) | |
ppv = 0 if not score else float(score) / sum(v) | |
if score > max_score or (score == max_score and ppv > max_ppv): | |
winner = book | |
max_score = score | |
max_ppv = ppv | |
elif score == max_score and ppv == max_ppv: | |
print 'WTF' | |
return | |
print "\nThe winner is...\n" | |
r = random.randint(1, 100) | |
if (r > 50): | |
print "\t" + winner | |
else: | |
print "\tDragons" | |
if __name__ == '__main__': | |
votes = { | |
'Software Oriented Architecture' : [1, 2, 4], | |
'Design Patterns' : [2, 2, 0], | |
'Dependency Injection' : [3, 1, 4], | |
'Domain Modeling' : [2, 4, 2], | |
'Enterprise Integration' : [0, 0, 0], | |
'Event Driven Programming' : [0, 0, 1] | |
} | |
tally(votes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment