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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/usr/bin/env python3
import re
import sys
# Order of all "k" elements
order = "NPSCD"
k = len(order)
# Weights of the elements (in the above order)
stuff = [
(4, "Nuzzles", 700),
(-1, "Prittles", 400),
(8, "Skipples", 1000),
(10, "Crottles", 2500),
(20, "Dupples", 200),
]
weights = [item[2] for item in stuff]
counts = [item[0] for item in stuff]
matrix = []
for line in sys.stdin:
line = line.strip()
if line == "unsat":
sys.exit('unsat!')
if line == "sat":
continue
m = re.match(r'([A-Z])(\d+) -> (\d+)', line)
item_type, trucknr, value = m.groups()
trucknr, value = int(trucknr), int(value)
# Map letter to column
col = order.index(item_type)
# auto-detect size, extending matrix size if necessary.
while len(matrix) < trucknr:
matrix.append([None] * k)
matrix[trucknr - 1][col] = value
# Number of trucks
n = len(matrix)
line = " "
for col in range(k):
line += " & %5s" % order[col]
line += " & weight"
line += r" & \#pallets"
line += r" \\"
print(line)
print(r"\hline")
for step, cells in enumerate(matrix):
# Add truck nr
line = "%2d" % (step + 1)
# Add building blocks and calculate weight and number of pallets
weight = 0
number_of_pallets = 0
for col, value in enumerate(cells):
line += " & %5d" % value
number_of_pallets += value
weight += value * weights[col]
# Add weight and number of pallets
line += " & %5d & %d" % (weight, number_of_pallets)
line += r" \\"
print(line)
# Print the total numbers
line = " "
helperline = "% " # for displaying the expected counts
for col in range(len(matrix[0])):
total_pallets_for_item = sum(truck[col] for truck in matrix)
line += " & %5d" % total_pallets_for_item
helperline += " & %5d" % counts[col]
print(r"\hline")
print(line)
#print(helperline)
|