Tic-Tac-Toe Implemented In Single Call To Printf():
[Nicholas Carlini] programmed a C implementation of two-player Tic Tac Toe, and he did it in a single call to printf(). The arguments for that single function call get mind-bendingly complex, so it may come as no surprise that it was written for The International Obfuscated C Code Contest (IOCCC).
Most of us are aware that printf() is one of those functions that is considerably more complex under the hood, and capable of far more, than it may appear to be. But did you know that it is capable of Turing-complete computation?
Can't wait to see the version that can play checkers and chess!
(Score: 4, Interesting) by looorg on Saturday June 06 2020, @04:49PM (5 children)
As much as I like this, and I always enjoy this kind of things, I can't help but at the same time think -- so what? It's not in a single Printf, it's in a single call of printf to activate it all. There is a fair amount of defines and setup that just gets called once then to get the ball rolling. I was when I saw the headline thinking that this is gonna be one hell of a printf line. So in that regard it was a bit of a disappointment. Also a lot of the defines and setup are just there to obfuscate instead of writing things plainly. Which he explains.
I have no idea if it's a good tic-tac-toe program, I didn't bother compiling it or test it and I can't really tell just by looking at it -- not that I gave it that much thought or time. How does it evaluate moves or does it just plonk down a symbol in whatever square is available? Randomly? First available space? He doesn't explain move-evaluation as far as I can tell.
Is this one of the rules of tic-tac-toe? I can't really remember ever having that issue. What would be an illegal move? Plonking down a number/symbol in an already occupied space? Sometimes people don't like or let you start by putting a number in the center square etc. But I don't think I ever heard of illegal moves in tic-tac-toe before. What would they be?
(Score: 0) by Anonymous Coward on Saturday June 06 2020, @05:54PM (3 children)
From TFS:
(Score: 2) by looorg on Saturday June 06 2020, @06:18PM (1 child)
Yes. I did read that to. But considering that he explained a lot of other things he did one could perhaps expect or wonder how he evaluated moves in the game. Considering that is a fairly important aspect of tic-tac-toe.
(Score: 0) by Anonymous Coward on Saturday June 06 2020, @07:51PM
A fair point.
I focused on the "obfuscated" part. :)
(Score: 0) by Anonymous Coward on Sunday June 07 2020, @01:26PM
That's not exactly an explanation now is it?
(Score: 3, Interesting) by KritonK on Sunday June 07 2020, @10:20AM
It isn't. It simply manages the board, on which two humans take turns, playing against each other.