对那个IOCCC程序的进一步分析时间:2023-01-30 13:30:57在去年暑假,曾经尝试过化简该程序,最终以失败告终;昨天晚上没事干,又把它拿了出来,终于成功化简了。。 原程序: #include <stdio.h> main(t,_,a) char *a; { return!0<t?t<3?main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)): 1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13? main(2,_+1,"%s %d %d/n"):9:16:t<0?t<-72?main(_,t, "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#/ ;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l / q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# / ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' / iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c / ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')#/ }'+}##(!!/") :t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1) :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a, "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:/nuwloca-O;m .vpbks,fxntdCeghiry"),a+1); } 初步化简版: #include <cstdio> #define STR_0 "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#/ ;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l / q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# / ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' / iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c / ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')#/ }'+}##(!!/" #define STR_1 "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:/nuwloca-O;m .vpbks,fxntdCeghiry" int work(int t, int m, int n) { if (t > 1) { if (t < 3) work(-79, -13, n + work(-87 ,1 - m, work(-86, 0, n + 1) + n)); if (t < m) work(t + 1, m, n); if (work(-94, -27 + t, n) && t == 2) { if (m < 13) return work(2, m + 1, (int)"%s %d %d/n"); else return 9; } else return 16; } else { if (t < 0) { if (t < -72) return work(m, t, (int)STR_0); if (t < -50) { if (m == *(char*)n) return putchar(*((char*)n + 31)); else return work(-65, m, n + 1); }else return work((*(char*)n == '/') + t, m, n + 1); } if (t > 0) return work(2, 2, (int)"%s"); if (*(char*)n == '/') return 1; return work(0, work(-61, *(char*)n, (int)STR_1), n + 1); } } int main() { work(1, 0, 0); } 最终化简版: /* * $File: mg.cpp * $Date: Sat Jun 19 00:43:58 2010 +0800 * * Simplified version of a IOCCC program. * * Original code of that program (base64): I2luY2x1ZGUgPHN0ZGlvLmg+Cm1haW4odCxfLGEpCmNoYXIgKmE7CnsKcmV0dXJuITA8dD90PDM/ bWFpbigtNzksLTEzLGErbWFpbigtODcsMS1fLG1haW4oLTg2LDAsYSsxKSthKSk6CjEsdDxfP21h aW4odCsxLF8sYSk6MyxtYWluKC05NCwtMjcrdCxhKSYmdD09Mj9fPDEzPwptYWluKDIsXysxLCIl cyAlZCAlZFxuIik6OToxNjp0PDA/dDwtNzI/bWFpbihfLHQsCiJAbicrLCMnLyp7fXcrL3cjY2Ru ci8rLHt9ci8qZGV9KywvKnsqKywvd3slKywvdyNxI24rLC8je2wrLC9ue24rLC8rI24rLC8jXAo7 I3EjbissLytrIzsqKywvJ3IgOidkKiczLH17dytLIHcnSzonK31lIyc7ZHEjJ2wgXApxIycrZCdL IyEvK2sjO3EjJ3J9ZUtLI313J3J9ZUtLe25sXScvIzsjcSNuJyl7KSN9dycpeyl7bmxdJy8rI24n O2R9cncnIGk7IyBcCil7bmxdIS9ue24jJzsgcnsjdydyIG5je25sXScvI3tsLCsnSyB7cncnIGlL eztbe25sXScvdyNxI24nd2sgbncnIFwKaXdre0tLe25sXSEvd3slJ2wjI3cjJyBpOyA6e25sXScv KntxIydsZDtyJ317bmx3YiEvKmRlfSdjIFwKOzt7bmwnLXt9cnddJy8rLH0jIycqfSNuYywnLCNu d10nLytrZCcrZX0rOyMncmRxI3chIG5yJy8gJykgfSt9e3JsIyd7bicgJykjXAp9Jyt9IyMoISEv IikKICA6dDwtNTA/Xz09KmE/cHV0Y2hhcigzMVthXSk6bWFpbigtNjUsXyxhKzEpOm1haW4oKCph PT0nLycpK3QsXyxhKzEpCiAgICA6MDx0P21haW4oMiwyLCIlcyIpOiphPT0nLyd8fG1haW4oMCxt YWluKC02MSwqYSwKIiFlaztkYyBpQGJLJyhxKS1bd10qJW4rcjMjbCx7fTpcbnV3bG9jYS1PO20g LnZwYmtzLGZ4bnRkQ2VnaGlyeSIpLGErMSk7Cn0K * */ #include <cstdio> static const char *STR_0 = "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#" ";#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l " "q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# " "){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' " "iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c " ";;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')#" "}'+}##(!!/"; static const char *STR_1 = "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:/nuwloca-O;m .vpbks,fxntdCeghiry"; /* "On the /first/second/third/fourth/fifth/sixth/seventh/eigth/ninth/tenth/e" "leventh/twelfth/ day of Christmas my true love ga" "ve to me_/twelve drummers drumming, /eleven pipers piping, /ten lords a-lea" "ping,_/nine ladies dancing, /eight maids a-milking, /seven swans a" "-swimming,_/six geese a-laying, /five gold rings;_/four ca" "lling birds, /three french hens, /two turtle doves_and /a partridge in a pe" "r tree.__/" (_ means '/n') */ static void work(int t, int m); static void jmp_slash(int cnt); void work(int t, int m) { if (t == 2) { jmp_slash(0); // on the jmp_slash(m - 1); // xx th jmp_slash(13); // day ... gave to me /n } if (t < m) work(t + 1, m); jmp_slash(27 - t); if (t == 2 && m < 13) work(2, m + 1); } void jmp_slash(int cnt) { const char *ptr = STR_0; while (cnt) cnt -= (*(ptr ++) == '/'); while (*ptr != '/') { const char *p1 = STR_1; while (*ptr != *p1) p1 ++; printf("%c", p1[31]); ptr ++; } } int main() { work(2, 2); } 原程序的作者能把一个程序写成这样,确实很不容易,敬礼!