1. 程式人生 > >列印自身的程式(python和c版)

列印自身的程式(python和c版)

python版

me='me=%r\nprint me %% me'
print me % me

網上流傳的c版
#include <stdio.h>
char* recurse = "#include <stdio.h>%cchar* recurse=%c%s%c;%cvoid main(){printf(recurse,10,34,recurse,34,10,10);}%c";
void main(){printf(recurse,10,34,recurse,34,10,10);}

參考文獻:

[1] 《Introduction to the Theory of Computation》Michael Sipser  chapter 6

[2] 《哥德爾、艾舍爾、巴赫》侯世達

[3] 《複雜》梅拉妮·米歇爾

[4] 《Theory of Self-Reproducing Automata》 John von Neumann