5

Another SO question mentions a fantastic quine by Yusuke Endoh. A quine is a computer program which produces a copy of its own source code as its only output; this one does it with a twist. A must-see.

But I can't figure out how it works. Any pointers?

Community
  • 1
  • 1
steenslag
  • 79,051
  • 16
  • 138
  • 171
  • The comments on that post are a decent start. – Anon. Dec 21 '10 at 21:47
  • 2
    +1 for the pun on "twist". There's a YouTube showing it stepping by 1 degree through the full 360 degree rotation [here](http://www.youtube.com/watch?v=ktq-22iq-Po) that is amusing to watch. Note the only other flickering text is at the upper left where `v` is defined. – RBerteig Apr 03 '11 at 21:51

1 Answers1

6

First, note that the v= line and the ASCII globe are the only bits of the code that change on each generation. This gives us a bit of a hint as to what's really going on here.

The basic principle is that the globe model was encoded with Zlib::Deflate in the first half of the code, and the second half expands it with Zlib::Inflate, reads it, and draws the ASCII globe within the new code, with the new v value. There's nothing particularly special about the 45° shifts; the code will draw the globe at whatever rotation you like. (In fact, it takes a command line argument specifying the number of degrees, if you like.)

For more implementation details, I'd recommend expanding the source code and tracing through it, with that basic understanding of how the quine is designed :)

Matchu
  • 83,922
  • 18
  • 153
  • 160