-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathexample.py
More file actions
26 lines (21 loc) · 654 Bytes
/
example.py
File metadata and controls
26 lines (21 loc) · 654 Bytes
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
from collections import Counter
PER_BOOK = 800.00
PER_GROUP = {
1: 1 * PER_BOOK * 1.00,
2: 2 * PER_BOOK * 0.95,
3: 3 * PER_BOOK * 0.90,
4: 4 * PER_BOOK * 0.80,
5: 5 * PER_BOOK * 0.75,
}
def _total(books):
volumes = Counter(books)
price = len(books) * PER_BOOK
for size in range(len(volumes), 1, -1):
group = volumes - Counter(k for k, _ in volumes.most_common(size))
group_books = sorted(group.elements())
price = min(price, PER_GROUP[size] + _total(group_books))
return price
def total(books):
if not books:
return 0
return _total(sorted(books))