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.


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00