genmain.py

Home   »   genmain.py

/usr/bin/env python3
N = 10
def p(x): print(x, end="")

# forward decl
p("int even(")
for i in range(N):
    if i > 0: p(", ")
    p("int")
p(");\n");

p("int odd(")

for i in range(N):
    if i > 0: p(", ")
    p(f"n{i}")
p(") {\n")
p("  return n0 == 0 ? 0 : ")
p("5*even("); 

for i in range(N):
    if i > 0: p(", ")
    p(f"n{i} - n{(i+1)%N}")
p (");");

p("\n}")
p("\n\n");


p("int even(")

for i in range(N):
    if i > 0: p(", ")
    p(f"n{i}")
p(") {\n")
p("  return n0 == 2 ? 0 : ")
p("3*odd("); 

for i in range(N):
    if i > 0: p(", ")
    p(f"n{i} - n{(i+1)%N}")
p (");");

p("\n}")

Leave a Reply

Your email address will not be published.