Sep. 5th, 2007

aparrish: (Default)
There comes a time in every person's life when he or she must quine. This evening, gentle readers, that bell tolled for me. I was pretty happy with my initial attempt in Python:
qu = '\x22\x22\x22'
def pr(p): print p; print "pr(r%s%s%s)" % (qu,p,qu)
pr(r"""qu = '\x22\x22\x22'
def pr(p): print p; print "pr(r%s%s%s)" % (qu,p,qu)""")

Not very advanced stuff, sure, but it gets the job done (without backticks!).

Here is an attempt to write a quine in Processing. The approach I used there is slightly different from the Python code above; it also draws its own source in the applet window, which is kind of fun. You can see the rigamarole I had to go through in order to cope with Java's (apparent) lack of a multiline quoting structure, along with my desire to keep the code easy to read.

Suggestions and feedback solicited: at this point, I'm just relieved to have finally understood the concept of a quine after all these years.

Links: More information on quines, Python quines written by people more clever than me.

March 2016

S M T W T F S
  12345
6789101112
13141516171819
20212223 242526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 18th, 2025 03:58 am
Powered by Dreamwidth Studios