Skip to content

Instantly share code, notes, and snippets.

@michaelxor
Created May 6, 2014 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelxor/1a5d1252425f7eea8cb5 to your computer and use it in GitHub Desktop.
Save michaelxor/1a5d1252425f7eea8cb5 to your computer and use it in GitHub Desktop.
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