-
Notifications
You must be signed in to change notification settings - Fork 2
/
answers.py
53 lines (37 loc) · 1.11 KB
/
answers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from output import Output
class Answers:
points = {
3 : 1,
4 : 1,
5 : 2,
6 : 3,
7 : 5,
8 : 11
}
def __init__(self):
self.words = set()
def add(self, words):
self.words.update(words)
def _make_dict(self):
words_by_length = {}
for word in sorted(self.words):
l = len(word)
if not words_by_length.has_key(l):
words_by_length[l] = []
words_by_length[l].append(word)
return words_by_length
def _calc_points(self):
total = 0
for word in self.words:
total += self.points[min(len(word), 8)]
return total
def __str__(self):
output = Output()
output.thick_bar()
output.add('Found {} words ({} points available)'.format(len(self.words), self._calc_points()))
words_by_length = self._make_dict()
for length in words_by_length:
output.thin_bar()
output.add('{}: {}'.format(length, ' '.join(words_by_length[length])))
output.thick_bar()
return str(output)