From a9a010623c75610cafe67d4ce7accc678f94937b Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 11 Jan 2017 18:23:31 +0100 Subject: WIP food delivery --- food_delivery/food-to-table.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 food_delivery/food-to-table.py (limited to 'food_delivery/food-to-table.py') diff --git a/food_delivery/food-to-table.py b/food_delivery/food-to-table.py new file mode 100755 index 0000000..c054f0c --- /dev/null +++ b/food_delivery/food-to-table.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +import re +import sys + +# Maximum number of elements +n = 5 + +matrix = [] +nextNodes = {} + +for line in sys.stdin: + line = line.strip() + if line == "unsat": + sys.exit('unsat!') + if line == "sat": + continue + m = re.match(r's(\d+)_(\d+) -> (\d+)', line) + if m: + villagenr, step, value = map(int, m.groups()) + + # auto-detect size, extending matrix size if necessary. + while len(matrix) <= step: + matrix.append([None] * n) + + matrix[step][villagenr] = value + else: + m = re.match(r'l(\d+) -> (\d+)', line) + step, value = map(int, m.groups()) + nextNodes[step] = value + +if False: + line = " " + for col in range(len(matrix[0])): + line += " & $a_%d$" % (col + 1) + line += r" \\" + print(line) + print(r"\hline") + +for step, cells in enumerate(matrix): + line = "%3d" % step + for col, value in enumerate(cells): + if nextNodes.get(step + 1) == col: + #line += r" & \bf%2d" % value + line += r" & %4d." % value + else: + line += " & %5d" % value + line += r" & %s \\" % "SABCD"[nextNodes[step]] + #line += r" \\" + print(line) -- cgit v1.2.1