Skip to content

Instantly share code, notes, and snippets.

@tomviner
Created February 24, 2016 19:36
Show Gist options
  • Save tomviner/df3c477c6912617badee to your computer and use it in GitHub Desktop.
Save tomviner/df3c477c6912617badee to your computer and use it in GitHub Desktop.
Who's been dojo herding a lot recently?
from __future__ import division, print_function
from collections import defaultdict
from operator import itemgetter
get_values = itemgetter(1)
last_few_herders = """
Nicholas
Gautier
Al
Tim
Tom
Tim
Al
Tom
Gautier
Nicholas
Dan
Tim
Gautier
Nicholas
Tom
Nicholas
Tim
""".strip().splitlines()
scores = defaultdict(int)
for dmonth, herder in enumerate(reversed(last_few_herders), 1):
score = 1 / (dmonth)
print('{:2d} {:10s} {:5.1f}%'.format(dmonth, herder, 100*score))
scores[herder] += score
print()
print("Who's been dojo herding a lot recently?")
total = sum(scores.values())
for herder, score in sorted(scores.items(), key=get_values, reverse=True):
print('{:.1f}%: {}'.format((100 * score / total), herder))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment