Pergunta

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?

Foi útil?

Solução

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 :)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top