C Icon

C

C is a general purpose programming language that first appeared in 1972.
1 Story
All Topics

C github.com

tic-tac-toe in a single call to printf

This was written for The International Obfuscated C Code Contest 2020 and I have zero idea how it works, but the entirety of the program consists of one call to printf

int main() {
    while(*d) printf(fmt, arg);
}

While its primary purpose is to serve as The One True Debugger, printf also happens to be Turing complete. (See “Control-Flow Bending: On the Effectiveness of Control-Flow Integrity” where we introduced this in an actual, published, academic paper. The things you can get away with sometimes.)

We ab^H^Huse this fact to implement a the logic of tic-tac-toe entirely within this one printf call (and a call to scanf() to read user input).

The code is beautifully formatted, too.

0:00 / 0:00