Created
June 27, 2012 10:09
-
-
Save fumieval/3003109 to your computer and use it in GitHub Desktop.
後輩にクワインを説明するためにCで作ったプログラム
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
data = open(sys.argv[1], "r").read() | |
print data.replace("$", chr(34) + data.replace("\n", "\\n") + chr(34)).strip("\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//自己複製を行うプログラム。 | |
const char gene[] = $; // DNAに相当する。プログラム全体の設計図が描かれており、DNAの場所にはドル記号が置かれている。 | |
int main(void) | |
{ | |
int i, j; | |
for (i = 0; gene[i] != 0; i++) //設計図から一文字ずつ読み込んで出力する。 | |
{ | |
if (gene[i] == 36) //ドル記号を見つけた場合、設計図を複製して出力する。 | |
{ | |
putchar(34); //設計図の両端にある引用符を出力する。 | |
for (j = 0; gene[j] != 0; j++) //設計図から一文字ずつ読み込んで複製していく。 | |
{ | |
if (gene[j] == 10) //改行はバックスラッシュと小文字のnで表現する。 | |
{ | |
putchar(92); | |
putchar(110); | |
} | |
else //それ以外の場合、そのまま出力する。 | |
{ | |
putchar(gene[j]); | |
} | |
} | |
putchar(34); | |
} | |
else //ドル記号以外の場合はそのまま出力する。 | |
{ | |
putchar(gene[i]); | |
} | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python build_quine.py quine.c.template > quine.c | |
gcc quine.c | |
./a.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment