Warning: is_readable() [function.is-readable]: open_basedir restriction in effect. File(D:\InetPub\vhosts\iasync-5360.package\karthiknadig.com\wwwroot/wp-content/plugins/http://karthiknadig.com/wp-content/plugins/lightbox-plus/languages/lightboxplus-en_US.mo) is not within the allowed path(s): (D:/InetPub/vhosts/iasync-5360.package\;C:\Windows\Temp\) in D:\InetPub\vhosts\iasync-5360.package\karthiknadig.com\wwwroot\wp-includes\l10n.php on line 556
Self-replicating program | Normal

Self-replicating program

Karthik Nadig

Self-replicating or self-copying programs are kind of interesting to play with. They are also called Quine. Here is one written in C, by Vlad Taeerov and Rashit Fakhreyev.

main(a)
{
    printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);
}

I adjusted it to work on Code::Blocks:

#include <stdio.h>
main(char*a)
{
  printf(
    a,
    34,
    a="#include <stdio.h>\nmain(char*a){printf(a,34,a=%c%s%c,34);}",
    34);
}

This a prolog version I created:

q :-
        listing(q),
        write(':-q.').
 
:-q.

It could have been shorter, but you would have to query ‘q’. This is it:

q:-listing(q).

One Response to “Self-replicating program”

Leave a Reply