Very Smart Programming Riddle

This topic is 4278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello, I saw in one of the forums quite smart riddle: You should write a program which writes itself. This question and answer raised in very interesting article. If you want the article just ask but first- try to answer it by yourself.

Share on other sites
Programs that write themselves out are called quines, and there have been several of them out there for almost any language.

Share on other sites
In perl, Yeah, i know, i cheat :)

#!/usr/bin/perlseek DATA,SEEK_SET,0; print <DATA>;__DATA__

Share on other sites
Quines are pretty straightforward in most languages. Write a program that prints a string twice, make the string the same as the code, and tweak it a little.

Share on other sites
More information on quines is available from Wikipedia. It has two sample quines written in both C and BASIC.