csci5607/assignment-2b/make_statements.py

27 lines
609 B
Python
Raw Normal View History

2023-04-26 00:52:54 +00:00
def mkslot(m, i, j):
ij = j + i * 4
return f"{m}[{ij}]"
# return m + "xyzw"[i] + str(j + 1)
def mm(leftcalled = "l", rightcalled = "r"):
stmts = []
for i in range(4):
for j in range(4):
res = mkslot("m", i, j)
terms = []
for k in range(4):
left = mkslot(leftcalled, i, k)
right = mkslot(rightcalled, k, j)
term = f"{left} * {right}"
terms.append(term)
stmt = f"{res} = {' + '.join(terms)};"
stmts.append(stmt)
return "\n".join(stmts)
print(mm())