FuckyWucky/nester.py

37 lines
1004 B
Python
Raw Permalink Normal View History

2019-05-07 17:57:03 +00:00
limit = 25
print("package net.ahines.DeepNested;")
print("class DeepNested {")
print("\tpublic static void main(String args[]) {")
print("\t\tNested1 nested1 = new Nested1(0.0);")
print("\t}")
class_name = "Nested%d"
class_header = "public static class %s {"
for i in range(1, limit):
tab_str = "\t"
for x in range(0, i):
tab_str += "\t"
nested_name = class_name % i
nested_header = class_header % nested_name
print(tab_str + nested_header)
print(tab_str + "\t" + nested_name + "(double sum) {")
print(tab_str + "\t\t" + ("sum += ((-1)^(%d+1)) / (2.0 * %d - 1.0);" % (i, i))) # copied from stack overflow
if (i == limit-1):
print(tab_str + "\t\tSystem.out.println(sum);")
else:
print(tab_str + "\t\tNested%d test%d = new %s(sum);" % (i+1, i, class_name % (i+1)))
print(tab_str + "}")
print("\n")
for i in range(limit, 1, -1):
tab_str = ""
for x in range(0, i):
tab_str += "\t"
print(tab_str + "}")
print("}")