#!/usr/bin/env python3
import sys
+import re
trucks = {}
pallets = {'p': 'Prittles', 'n': 'Nuzzles', 'c': 'Crottles',
's': 'Skipples', 'd': 'Dupples'}
for line in sys.stdin:
- if line.startswith('(='):
- truck = line[4]
- pallet = line[5]
-
- number = int(line[7:-2])
- trucks[truck] = trucks.get(truck, {})
- trucks[truck][pallets[pallet]] = number
+ match = re.match('\(= t(?P<t>\d+)(?P<p>.) (?P<v>\d+)\)', line)
+ if match:
+ trucks[match.group('t')] = trucks.get(match.group('t'), {})
+ trucks[match.group('t')][pallets[match.group('p')]] = \
+ int(match.group('v'))
print('$\\begin{array}{|l|lllll|}')
print('\t\\toprule')
-print('\tTruck & {}\\\\'.format(' & '.join(sorted(pallets.values()))))
+print('\t\\text{{Truck}} & {}\\\\'.format(
+ ' & '.join('\\text{{{}}}'.format(p) for p in sorted(pallets.values()))))
print('\t\\midrule')
for truck in sorted(trucks):
print('\t{} & {}\\\\'.format(truck, ' & '.join(
str(p[1]) for p in sorted(trucks[truck].items()))))
print('\t\\midrule')
-print('\tTotal & {}\\\\'.format(' & '.join(
+print('\t\\text{{Total}} & {}\\\\'.format(' & '.join(
str(sum(t[p] for t in trucks.values())) for p in
sorted(pallets.values()))))
print('\t\\bottomrule')