{"id":1616,"date":"2015-02-02T09:23:49","date_gmt":"2015-02-02T08:23:49","guid":{"rendered":"http:\/\/roboblog.fatal-fury.de\/?p=1616"},"modified":"2015-02-02T11:09:26","modified_gmt":"2015-02-02T10:09:26","slug":"more-crazy-c","status":"publish","type":"post","link":"http:\/\/roboblog.fatal-fury.de\/?p=1616","title":{"rendered":"more crazy C"},"content":{"rendered":"<p>#include <stdio.h><\/p>\n<p>#define CACHE 256<br \/>\nenum { h_unknown = 0, h_yes, h_no };<br \/>\nunsigned char buf[CACHE] = {0, h_yes, 0};<\/p>\n<p>int happy(int n)<br \/>\n{<br \/>\n\tint sum = 0, x, nn;<br \/>\n\tif (n < CACHE) {\n\t\tif (buf[n]) return 2 - buf[n];\n\t\tbuf[n] = h_no;\n\t}\n \n\tfor (nn = n; nn; nn \/= 10) x = nn % 10, sum += x * x;\n \n\tx = happy(sum);\n\tif (n < CACHE) buf[n] = 2 - x;\n\treturn x;\n}\n \nint main()\n{\n\tint i, cnt = 8;\n\tfor (i = 1; cnt || !printf(\"\\n\"); i++)\n\t\tif (happy(i)) --cnt, printf(\"%d \", i);\n \n\tprintf(\"The %dth happy number: \", cnt = 1000000);\n\tfor (i = 1; cnt; i++)\n\t\tif (happy(i)) --cnt || printf(\"%d\\n\", i);\n \n\treturn 0;\n}\n\nfrom <a href=\"http:\/\/rosettacode.org\/wiki\/Happy_numbers#C\">http:\/\/rosettacode.org\/wiki\/Happy_numbers#C<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include #define CACHE 256 enum { h_unknown = 0, h_yes, h_no }; unsigned char buf[CACHE] = {0, h_yes, 0}; int happy(int n) { int sum = 0, x, nn; if (n < CACHE) { if (buf[n]) return 2 - buf[n]; buf[n] = h_no; } for (nn = n; nn; nn \/= 10) x = nn [&hellip;]\n<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[14],"class_list":["post-1616","post","type-post","status-publish","format-standard","hentry","category-allgemein","tag-c"],"_links":{"self":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/1616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1616"}],"version-history":[{"count":2,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/1616\/revisions"}],"predecessor-version":[{"id":2164,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/1616\/revisions\/2164"}],"wp:attachment":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1616"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}