Saturday, April 23, 2011

An even shorter quine

While on the topic of self-reproducing programs or "quines" as they are called, I was watching Hilary Mason's keynote at Pycon 2011. It was very interesting to hear her talk about data science - how its gaining ground, and how Python provides great tools to dig into it.
One interesting thing was she showed a quine in one of her slides, and it was much shorter than the one I came up with. I think she said the source of it was Godel, Escher, Bach.
Here it is:

a = 'print "a=", repr(a);print "exec(a)"'
exec(a)
To me this is a shorter, elegant quine. Still have to figure out how to arrive at it, though.

No comments:

Post a Comment