Skip to content

Instantly share code, notes, and snippets.

@tomviner
Last active February 24, 2016 21:47
Show Gist options
  • Save tomviner/b4378d186bad36421cd6 to your computer and use it in GitHub Desktop.
Save tomviner/b4378d186bad36421cd6 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)
print('Months ago | Herder | Weight')
for dmonth, herder in enumerate(reversed(last_few_herders), 1):
score = 1 / (dmonth)
print('{:10d} | {:10} | {:5.0f}%'.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('{:3.0%} {}'.format((score / total), herder))
Months ago | Herder | Weight
1 | Tim | 100%
2 | Nicholas | 50%
3 | Tom | 33%
4 | Nicholas | 25%
5 | Gautier | 20%
6 | Tim | 17%
7 | Dan | 14%
8 | Nicholas | 12%
9 | Gautier | 11%
10 | Tom | 10%
11 | Al | 9%
12 | Tim | 8%
13 | Tom | 8%
14 | Tim | 7%
15 | Al | 7%
16 | Gautier | 6%
17 | Nicholas | 6%
Who's been dojo herding a lot recently?
38% Tim
27% Nicholas
15% Tom
11% Gautier
5% Al
4% Dan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment