started with a2
[ar1516.git] / a1 / src / a1.py
1 #!/usr/bin/env python3
2 import sys
3 import re
4
5 trucks = {}
6 pallets = {'p': 'Prittles', 'n': 'Nuzzles', 'c': 'Crottles',
7 's': 'Skipples', 'd': 'Dupples'}
8
9 for line in sys.stdin:
10 match = re.match('\(= t(?P<t>\d+)(?P<p>.) (?P<v>\d+)\)', line)
11 if match:
12 trucks[match.group('t')] = trucks.get(match.group('t'), {})
13 trucks[match.group('t')][pallets[match.group('p')]] = \
14 int(match.group('v'))
15
16 print('$\\begin{array}{|l|lllll|}')
17 print('\t\\toprule')
18 print('\t\\text{{Truck}} & {}\\\\'.format(
19 ' & '.join('\\text{{{}}}'.format(p) for p in 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('\t\\text{{Total}} & {}\\\\'.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}$')