Stories
Slash Boxes
Comments

SoylentNews is people

SoylentNews is powered by your submissions, so send in your scoop. Only 19 submissions in the queue.
posted by martyb on Saturday June 06 2020, @04:06PM   Printer-friendly
from the your-move dept.

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!


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
(1)
  • (Score: 4, Funny) by Anonymous Coward on Saturday June 06 2020, @04:12PM (4 children)

    by Anonymous Coward on Saturday June 06 2020, @04:12PM (#1004216)

    Poettering reads this article and decides to implement printf() in SystemD.

    • (Score: 2) by RS3 on Saturday June 06 2020, @06:43PM

      by RS3 (6367) on Saturday June 06 2020, @06:43PM (#1004272)

      Poettering reads this article and decides to implement printf() in SystemD. decries "Hey, someone pirated my systemd code!"

    • (Score: 3, Informative) by DECbot on Saturday June 06 2020, @11:09PM

      by DECbot (832) on Saturday June 06 2020, @11:09PM (#1004359) Journal

      printfctl --turn=x --tictactoe=TOP-LEFT | systemctl reload tictactoed | journalctl -u tictactoed.service && systemctl --minesweeper=fair restart networking

      --
      cats~$ sudo chown -R us /home/base
    • (Score: 0) by Anonymous Coward on Sunday June 07 2020, @04:24AM (1 child)

      by Anonymous Coward on Sunday June 07 2020, @04:24AM (#1004409)

      You're not as clever as you think you are.

      • (Score: 1, Touché) by Anonymous Coward on Sunday June 07 2020, @11:17AM

        by Anonymous Coward on Sunday June 07 2020, @11:17AM (#1004468)

        +4 up-votes say otherwise, Lennart.

  • (Score: 1, Insightful) by Anonymous Coward on Saturday June 06 2020, @04:18PM (1 child)

    by Anonymous Coward on Saturday June 06 2020, @04:18PM (#1004220)

    These guys would have a field day with APL.

    Back then, there used to be all sorts of one-line code porn, like this one line of APL code that could draw an elephant.

    • (Score: 2) by driverless on Sunday June 07 2020, @04:03AM

      by driverless (4770) on Sunday June 07 2020, @04:03AM (#1004408)

      there used to be all sorts of one-line code porn, like this one line of APL code that could draw an elephant.

      So a single line of APL could generate all of systemd as its output? Wow.

  • (Score: 1, Insightful) by Anonymous Coward on Saturday June 06 2020, @04:36PM (3 children)

    by Anonymous Coward on Saturday June 06 2020, @04:36PM (#1004225)

    With properly initialized variables, I can reduce the contents of my entire hard drive or even the whole internet to the same line of code.

    This is going to be a huge breakthrough for data compression.

    • (Score: 4, Funny) by sgleysti on Sunday June 07 2020, @02:39AM (1 child)

      by sgleysti (56) Subscriber Badge on Sunday June 07 2020, @02:39AM (#1004395)

      How else do you think the big bang happened?

      • (Score: 0) by Anonymous Coward on Sunday June 07 2020, @04:36PM

        by Anonymous Coward on Sunday June 07 2020, @04:36PM (#1004544)

        In sufficient number that all parameters could be set randomly at runtime, eliminating the need for any inputs.

    • (Score: 0) by Anonymous Coward on Sunday June 07 2020, @01:24PM

      by Anonymous Coward on Sunday June 07 2020, @01:24PM (#1004491)

      Exactly. The code is actually dozens of lines long. Calling it "1 line" is like saying MS Word is only 1 line because all you need to type is word.exe.

  • (Score: 2, Informative) by Anonymous Coward on Saturday June 06 2020, @04:40PM

    by Anonymous Coward on Saturday June 06 2020, @04:40PM (#1004227)

    So, not really.

  • (Score: 4, Interesting) by looorg on Saturday June 06 2020, @04:49PM (5 children)

    by looorg (578) on Saturday June 06 2020, @04:49PM (#1004237)

    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.

    A player makes an illegal move; their opponent wins

    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)

      by Anonymous Coward on Saturday June 06 2020, @05:54PM (#1004259)

      He doesn't explain move-evaluation as far as I can tell.

      From TFS:

      it may come as no surprise that it was written for The International Obfuscated C Code Contest [ioccc.org] (IOCCC).

      • (Score: 2) by looorg on Saturday June 06 2020, @06:18PM (1 child)

        by looorg (578) on Saturday June 06 2020, @06:18PM (#1004265)

        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

          by Anonymous Coward on Saturday June 06 2020, @07:51PM (#1004299)

          A fair point.

          I focused on the "obfuscated" part. :)

      • (Score: 0) by Anonymous Coward on Sunday June 07 2020, @01:26PM

        by Anonymous Coward on Sunday June 07 2020, @01:26PM (#1004492)

        That's not exactly an explanation now is it?

    • (Score: 3, Interesting) by KritonK on Sunday June 07 2020, @10:20AM

      by KritonK (465) on Sunday June 07 2020, @10:20AM (#1004459)

      I have no idea if it's a good tic-tac-toe program

      It isn't. It simply manages the board, on which two humans take turns, playing against each other.

  • (Score: 2) by ChrisMaple on Saturday June 06 2020, @04:58PM

    by ChrisMaple (6964) on Saturday June 06 2020, @04:58PM (#1004240)

    In konsole, in bash. The game works. Scrolling up when done, there were screens-full of garbage.

  • (Score: 1, Informative) by Anonymous Coward on Saturday June 06 2020, @05:51PM (4 children)

    by Anonymous Coward on Saturday June 06 2020, @05:51PM (#1004257)

    From the source [github.com]:

    char d[538] = {1,0,10,0,10};
    int main() {
            while(*d) printf(fmt, arg);
    }

    • (Score: 2) by RS3 on Saturday June 06 2020, @06:39PM (3 children)

      by RS3 (6367) on Saturday June 06 2020, @06:39PM (#1004271)

      I only see 1 printf. If while executes printf more than once, then while was passed bad parameters, the error likely due to a spectre or meltown vulnerability.

      :)

      • (Score: 1, Interesting) by Anonymous Coward on Saturday June 06 2020, @07:21PM (2 children)

        by Anonymous Coward on Saturday June 06 2020, @07:21PM (#1004280)

        What do you mean? *d is initially 1, so the while loop would be infinite unless there is an assignment of 0 to d[0] at some point, which is probably this obfuscated vm's version of exit().

        • (Score: 2) by RS3 on Saturday June 06 2020, @09:00PM (1 child)

          by RS3 (6367) on Saturday June 06 2020, @09:00PM (#1004323)

          I was joking. Can you see the :) smiley? Maybe you're not aware of smileys?

          • (Score: 4, Funny) by sgleysti on Sunday June 07 2020, @02:41AM

            by sgleysti (56) Subscriber Badge on Sunday June 07 2020, @02:41AM (#1004396)

            I was joking. Can you see the smiley? Maybe you're not aware of smileys?

            Unfortunately, I have no idea what you're referring to. :(

  • (Score: 2) by bzipitidoo on Saturday June 06 2020, @10:02PM

    by bzipitidoo (4388) on Saturday June 06 2020, @10:02PM (#1004342) Journal

    Though, I admit to it being a bit cheap :D. And, it's definitely more conveniently done with fputs, so you don't have to redirect stdout.

    Just puts() the source code of whatever tic-tac-toe program you like to an appropriately named file, use an exec call to run cc to compile it, then another exec call to run the just compiled program.

  • (Score: 0) by Anonymous Coward on Sunday June 07 2020, @04:55PM

    by Anonymous Coward on Sunday June 07 2020, @04:55PM (#1004552)

    ...to say "Hi" to Wink Martindale for me.

(1)