Home » programming » A program that prints itself

A program that prints itself

We use a string that contains all the following code of the program. Then, we print the preamble and twice this string. We employ some tricks to easily print special characters like quotes.

code = """print('code = ""', end='"')
print(code + '"' + '""')
print(code, end='')
"""
print('code = ""', end='"')
print(code + '"' + '""')
print(code, end='')
Advertisements

2 Comments

  1. Errikos says:

    Softcore σε βρίσκω…
    Τσίμπα αυτό!
    http://pastebin.com/FCZFWNBv

    • dimle says:

      Ένα αντίστοιχο πρόγρμμα μπορεί να γραφτεί σε οποιαδήποτε Turing-complete γλώσσα προγραμματισμού. Αυτό που είναι ακόμα πιο εντυπωσιακό, είναι το ακόλουθο:

      The recursion theorem shows that no computable function is fixed point free, but there are many non-computable fixed-point free functions. [1]

      [1] http://en.wikipedia.org/wiki/Kleene%27s_recursion_theorem

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: