summaryrefslogtreecommitdiff
path: root/food_delivery/food-to-table.py
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2017-01-11 18:23:31 +0100
committerPeter Wu <peter@lekensteyn.nl>2017-01-11 18:23:31 +0100
commita9a010623c75610cafe67d4ce7accc678f94937b (patch)
tree3e834aaa35bbd3592b52d6d37e957f657573fa7b /food_delivery/food-to-table.py
parentc6224d0972607830cd63b97d6eb1e54168fa29f8 (diff)
download2IMF25-AR-a9a010623c75610cafe67d4ce7accc678f94937b.tar.gz
WIP food delivery
Diffstat (limited to 'food_delivery/food-to-table.py')
-rwxr-xr-xfood_delivery/food-to-table.py49
1 files changed, 49 insertions, 0 deletions
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)