{"id":6535,"date":"2024-04-16T12:19:47","date_gmt":"2024-04-16T06:49:47","guid":{"rendered":"https:\/\/www.suramya.com\/blog\/?p=6535"},"modified":"2024-04-15T20:44:18","modified_gmt":"2024-04-15T15:14:18","slug":"creating-a-tic-tac-toe-game-using-a-single-printf-statement-in-a-loop","status":"publish","type":"post","link":"https:\/\/www.suramya.com\/blog\/2024\/04\/creating-a-tic-tac-toe-game-using-a-single-printf-statement-in-a-loop\/","title":{"rendered":"Creating a Tic-Tac-Toe game using a single printf statement in a loop"},"content":{"rendered":"<p>The printf statement in C\/C++ (and other languages) is a fairly innocuous command that prints information to the screen (or any other output stream). Reading over JWZ&#8217;s blog post (<a href=\"https:\/\/www.jwz.org\/blog\/2024\/04\/the-turing-police-say-x-wins\/\">The Turing Police say &#8220;X Wins&#8221;<\/a>) I found that I was mistaken as it is much more powerful than that. In fact, a single printf statement in a loop can be used to create a full interactive game of tic-tac-toe and this is demo&#8217;d by Nicholas Carlini, who has implemented this and you can view the code over at their <a href='https:\/\/github.com\/carlini\/printf-tac-toe'>GitHub Repo: tic-tac-toe in a single call to printf<\/a>. <\/p>\n<p>Apparently, this was inspired by the <a href=\"http:\/\/www.ioccc.org\/\">International Obfuscated C Code Contest<\/a>. The repo has an explanation on how this works and I am still going through it to wrap my head around how it works and understand it fully. Check it out if you have some time.<\/p>\n<p>&#8211; Suramya<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The printf statement in C\/C++ (and other languages) is a fairly innocuous command that prints information to the screen (or any other output stream). Reading over JWZ&#8217;s blog post (The Turing Police say &#8220;X Wins&#8221;) I found that I was mistaken as it is much more powerful than that. In fact, a single printf statement [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"","activitypub_status":"federated","footnotes":""},"categories":[18,15,4,2],"tags":[],"class_list":["post-6535","post","type-post","status-publish","format-standard","hentry","category-computer-software","category-interesting-sites","category-my-thoughts","category-techie-stuff"],"_links":{"self":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/6535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/comments?post=6535"}],"version-history":[{"count":4,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/6535\/revisions"}],"predecessor-version":[{"id":6545,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/posts\/6535\/revisions\/6545"}],"wp:attachment":[{"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/media?parent=6535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/categories?post=6535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.suramya.com\/blog\/wp-json\/wp\/v2\/tags?post=6535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}