update with dynamic solution for problem 1
[ar1516.git] / src / a1.py
1 #!/usr/bin/env python3
2 import sys
3
4 trucks = {}
5 pallets = {'p': 'Prittles', 'n': 'Nuzzles', 'c': 'Crottles',
6 's': 'Skipples', 'd': 'Dupples'}
7
8 for line in sys.stdin:
9 if line.startswith('(='):
10 truck = line[4]
11 pallet = line[5]
12
13 number = int(line[7:-2])
14 trucks[truck] = trucks.get(truck, {})
15 trucks[truck][pallets[pallet]] = number
16
17 print('$\\begin{array}{|l|lllll|}')
18 print('\t\\toprule')
19 print('\tTruck & {}\\\\'.format(' & '.join(sorted(pallets.values()))))
20 print('\t\\midrule')
21 for truck in sorted(trucks):
22 print('\t{} & {}\\\\'.format(truck, ' & '.join(
23 str(p[1]) for p in sorted(trucks[truck].items()))))
24 print('\t\\midrule')
25 print('\tTotal & {}\\\\'.format(' & '.join(
26 str(sum(t[p] for t in trucks.values())) for p in
27 sorted(pallets.values()))))
28 print('\t\\bottomrule')
29 print('\\end{array}$')