Skip to content

Instantly share code, notes, and snippets.

@postylem
Created August 16, 2013 19:03
Show Gist options
  • Save postylem/6252600 to your computer and use it in GitHub Desktop.
Save postylem/6252600 to your computer and use it in GitHub Desktop.
outputs a program that prints itself after n iterations.
# a clunky n-cycle (iterated quine) generator:
def quiner(n):
'''prints a program that will print itself after n iterations'''
quotes = '"'*3
toprint = ''
for i in range(1,n):
toprint += 'def q' + str(i) + '(x):'"""
quotes = '"'*3
print 'q""" + str(i+1) + "(' + quotes + x + quotes + ')'\n\n"
toprint += 'def q' + str(n) + '(x):'"""
quotes = '"'*3
print x
print ''
print 'q1(' + quotes + x + quotes + ')'"""
print toprint + '\n\nq1(' + quotes + toprint + quotes + ')'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment