Printf-Tac-Toe (github.com)

110 points by carlos-menezes 4 days ago

mrngm 2 hours ago

[2020], and written for IOCCC: The International Obfuscated C Code Contest.

This was awarded "Best of Show - abuse of libc" at the time[0]. See also the judges' remarks[1]:

This program consists of a single printf(3) statement wrapped in a while loop. You would not think that this would amount to much, but you would be very, very wrong. A clue to what is happening and how this works is encoded in the ASCII art of the program source.

[0] https://www.ioccc.org/2020/index.html

[1] https://www.ioccc.org/2020/carlini/index.html

JKCalhoun 7 hours ago

Contestant: "I'll take My Dirty Programming Secrets for 100, Alex."

Alex: "Its primary purpose is to serve as The One True Debugger."

(It has certainly served me well.)

idorozin 9 hours ago

This is both impressive and slightly terrifying. Format strings are way more powerful than most people realize.

ivanjermakov 3 hours ago

No surprise Log4J attack was that big. Amount of logic one can fit into text formatting is immense.

danbruc 11 hours ago

How did we end up with printf - within a loop - being Turing-complete? Was it designed that way from the beginning? Were new features added over time until we got there?

marmakoide 10 hours ago

Having something Turing-complete is surprisingly easy, and it hides everywhere. The repository have a small document that explains how you can use printf() as a computer : it can performs additions, logical union and negation, which is enough.

It was unintentional, but Ken Thompson being Ken Thompson, can't be 100% sure.

gwern 3 hours ago

List of examples: https://gwern.net/turing-complete

It was probably unintentional, yeah, I don't recall any mentions of early printf being overloaded to do stuff, nor is it clear why you would do that since you're using it in a much more convenient Turing-complete language already (C).

danbruc 9 hours ago

So there was no extension of the functionality over time, all the formats have been supported from day one?

st_goliath 9 hours ago

LoganDark 5 hours ago

To be fair, this is actually `scanf` and `printf` in a loop. The `scanf` is buried in the `arg` define.

binaryturtle 5 hours ago

That's the content why I check HN! :)