Skip to content

Commit 4219cdd

Browse files
committed
strip down solution
1 parent 48860fe commit 4219cdd

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

domain_model.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
def allocate(order, stock, shipments):
2-
allocations = []
3-
for source in [stock] + shipments:
4-
allocation = allocate_to(order, source)
5-
if allocated_completely(order, allocation):
6-
return allocation
7-
allocations.append(allocation)
8-
return combine_preferring_first(allocations)
2+
allocation = {}
3+
for source in shipments + [stock]:
4+
allocation.update(allocation_from(order, source))
5+
return allocation
96

10-
def allocate_to(order, source):
7+
def allocation_from(order, source):
118
return {
129
sku: source
1310
for sku, quantity in order.items()
1411
if sku in source
1512
and source[sku] > quantity
1613
}
17-
18-
def allocated_completely(order, allocation):
19-
return order.keys() == allocation.keys()
20-
21-
def combine_preferring_first(allocations):
22-
return {
23-
k: v
24-
for d in reversed(allocations)
25-
for k, v in d.items()
26-
}

0 commit comments

Comments
 (0)