{"id":229,"date":"2006-10-03T08:38:58","date_gmt":"2006-10-03T08:38:58","guid":{"rendered":"http:\/\/gaisan.com\/wordp\/?p=229"},"modified":"2009-12-19T23:41:13","modified_gmt":"2009-12-19T23:41:13","slug":"who-writes-code-like-this","status":"publish","type":"post","link":"http:\/\/gaisan.com\/blogs\/?p=229","title":{"rendered":"Who writes code like this?"},"content":{"rendered":"<p>The infamous <a href=\"http:\/\/www.ioccc.org\">International Obfuscated C Code<\/a> winner from 1984. I have a sizeable bet that it&#8217;s Bjarne Stroustroup, the inventor of C++. However, Brian Kernighan is also a possibility. Send me your thoughts based on coding style etc.<br \/>\n<code>int i;main(){for(;i[\"]<i;++i){--i;}\"];read('-'-'-',i+++\"hell\\\no, world!\\n\",'\/'\/'\/'));}read(j,i,p){write(j\/p+p,i---j,i\/i);}<\/code><br \/>\nAn explanation of the code goes something like this.<br \/>\n<code>int i;main(){for(;i[\"]i;++i){--i;}\"];read('-'-'-',i+++ \"hell\\<br \/>\no, world!\\n\",'\/'\/'\/'));}read(j,i,p){write(j\/p+p,i---j ,i\/i);}<br \/>\n==== add some whitespace ==========<br \/>\nint i;<br \/>\nmain()<br \/>\n{<br \/>\nfor (; i[\"]i;++i){--i;}\"]; read('-' - '-', i++ + \"hello, world!\\n\", '\/' \/ '\/'));<br \/>\n}<br \/>\nread(j, i, p)<br \/>\n{<br \/>\nwrite(j \/ p + p, i-- - j, i \/ i);<br \/>\n}<br \/>\n===== and char subtraced from itself is 0, and char or pointer divided by itself is 1 =====<br \/>\nint i;<br \/>\nmain()<br \/>\n{<br \/>\nfor (; i[\"]i;++i){--i;}\"]; read(0, i++ + \"hello, world!\\n\", 1));<br \/>\n}<br \/>\nread(j, i, p)<br \/>\n{<br \/>\nwrite(j \/ p + p, i-- - j, 1);<br \/>\n}<br \/>\n======= j is always 0, p is always 1, lets remove them ======<br \/>\nint i;<br \/>\nmain()<br \/>\n{<br \/>\nfor (; i[\"]i;++i){--i;}\"]; read(i++ + \"hello, world!\\n\"));<br \/>\n}<br \/>\nread(i)<br \/>\n{<br \/>\nwrite(0 \/ 1 + 1, i-- - 0, 1);<br \/>\n}<br \/>\n======= 0 \/ 1 + 1 is 1, subtracting 0 does nothing, decrementing a local variable this is never used afterward also does nothing =======<br \/>\nint i;<br \/>\nmain()<br \/>\n{<br \/>\nfor (; i[\"]i;++i){--i;}\"]; read(i++ + \"hello, world!\\n\"));<br \/>\n}<br \/>\nread(i)<br \/>\n{<br \/>\nwrite(1, i, 1);<br \/>\n}<br \/>\n======== replace read(i) with write(1, i, 1) =====<br \/>\nint i;<br \/>\nmain()<br \/>\n{<br \/>\nfor (; i[\"]i;++i){--i;}\"]; write(1, i++ + \"hello, world!\\n\", 1));<br \/>\n}<br \/>\n====== i[n] can be rewritten *(i + n) or *(n + i) ======<br \/>\nint i;<br \/>\nmain()<br \/>\n{<br \/>\nfor (; *(\"]i;++i){--i;}\" + i); write(1, \"hello, world!\\n\" + i++, 1));<br \/>\n}<br \/>\n=== as i gets incrimented, we dereference the next char of the string which is always non-zero till we hit the null terminator, all the matters is that the string is the same length as \"hello, world!\\n\" =====<br \/>\nint i;<br \/>\nmain()<br \/>\n{<br \/>\nfor (; *(\"hello, world!\\n\" + i); write(1, \"hello, world!\\n\" + i++, 1));<br \/>\n}<br \/>\n===== so now we can see we incriment i, printing out the next character of hello world till we hit the null terminator ====<br \/>\n<\/code><br \/>\nWith thanks to slashdot and Thomas Scovell (who has it <a href=\"http:\/\/www.thomasscovell.com\/tattoo.php\">tattooed<\/a> on his arm)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The infamous International Obfuscated C Code winner from 1984. I have a sizeable bet that it&#8217;s Bjarne Stroustroup, the inventor of C++. However, Brian Kernighan is also a possibility. Send me your thoughts based on coding style etc. int i;main(){for(;i[&#8220;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1700],"_links":{"self":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/229"}],"collection":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229"}],"version-history":[{"count":5,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":504,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions\/504"}],"wp:attachment":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}