blob: c538e1bc11ddea37f1286671f75aed7a464f868c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# Converts input to a .dzn file
# Usage: python 24_convert.py | minizinc 24a.mzn -
cmds = open("./input").read().strip().split("\n")
def convert_ops(cmds):
for c in cmds:
yield "i_" + c.split(" ")[0]
def convert_arg(a):
cons = "R" if a in {"x", "y", "z", "w"} else "Imm"
return "%s(%s)" % (cons, a)
def convert_args(cmds):
for c in cmds:
spl = c.split(" ")[1:]
if len(spl) == 1:
yield (convert_arg(spl[0]), "None")
else:
yield (convert_arg(spl[0]), convert_arg(spl[1]))
inp_ops = list(convert_ops(cmds))
inp_args = list(convert_args(cmds))
print("inp_ops = [ %s ];" % ", ".join(inp_ops))
print("inp_args = [| %s |];" % "|".join([",".join(x) for x in inp_args]))
|