• ulterno@programming.dev
    link
    fedilink
    English
    arrow-up
    22
    ·
    1 day ago

    That’s not even enough to get you a job these days.
    You now have to use:

    do {
        x = reinterpret_cast<int>(AI::Instance().ask("Do Something. Anything. Be efficient and productive. Use 10 tokens."));
    } while (x != 10);
    
    • Tetragrade@leminal.space
      link
      fedilink
      English
      arrow-up
      7
      ·
      6 hours ago

      This isn’t just a function, it’s a bold restatement of what it means to write code — a symphony of characters, questioning the very nature of the cutting edge language models that I want to beat with hammers.

    • melfie@lemy.lol
      link
      fedilink
      arrow-up
      5
      ·
      1 day ago

      You’re absolutely right! Who sets a variable these days without running it though a LLM?

    • cooligula@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 day ago

      I’d say Meta hiring someone to work on WhatsApp. Man, is that piece of software crap… Every update, a new UI bug/glitch appears

    • TheOakTree@lemmy.zip
      link
      fedilink
      arrow-up
      1
      ·
      1 day ago

      If only I could measure the quality of my paper purely by word count…

      I thought “a a a a a a” x100000 was thought-provoking and well tested.

  • OshaqHennessey@midwest.social
    link
    fedilink
    arrow-up
    60
    ·
    2 days ago
    function myFunction() {
      try {
        x = new Random().nextInt();
        if (x != 10) {
         throw "not 10";
        }
        else {
          return (10)
        }
        catch(err) {
          myFunction()
        }
      }
    }
    
    x = myFunction()
    

    Commit notes: Added error handling

    • ronigami@lemmy.world
      link
      fedilink
      arrow-up
      10
      ·
      1 day ago

      That’s only one advantage. In theory it does not necessarily terminate, so that’s another one.

  • untorquer@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    1 day ago

    Something like

    int *a = new int(10)
    
    Int*b = null
    
    While *b !=10 { b = rand(); a=new int(10)}
    
    Return *b
    

    I haven’t coded recently enough in c/c++ to remember syntax but the concept might work eventually if you’re lucky and have enough memory… Might need a time variant seed on the rand()…

  • edinbruh@feddit.it
    link
    fedilink
    English
    arrow-up
    39
    ·
    2 days ago

    For a time on Reddit (some years ago when I still used it) there was a trend of finding the worst way of implementing is_even(x: int) -> bool. My contribution to that was a function that ran Ackerman(x,x) flipping a Boolean at every iteration, and check if it was true or false at the end.

    It works btw, I will find the proof later

      • edinbruh@feddit.it
        link
        fedilink
        English
        arrow-up
        17
        ·
        edit-2
        2 days ago

        The implementation is not very exciting, I capture a variable in python. It could have been done more cleanly.

        1000041934

        The proof is this. But, I could have made mistakes, it was many years ago.

        1000041935

        Note that in python you’ll never be able to run is_even(5) the stack cannot handle it

        Edit: daaaamn, that variable is ugly as hell. I would never do things like that now.

        • squaresinger@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          3 hours ago

          It never occurred to me that you could assign fields to a function. I mean, it totally makes sense considering that functions are objects in Python. It just never occurred to me that this is a thing one can do. Crazy.

  • Mika@piefed.ca
    link
    fedilink
    English
    arrow-up
    24
    arrow-down
    1
    ·
    2 days ago

    I once was helping to organize the testing of town-level algorithmic competition for school students.

    The competition had one entry level issue that was basically solvable by reading the question properly, recognising that it’s just multiplication of two numbers, and writing the simplest app ever.

    And there was one student who passed the automatic tests. We had to read the code too for the protocol, just to make sure there was no cheating.

    We looked in the code. What? Why? It had two nested for loops and a++ inside. When we understood what’s going on we couldn’t stop laughing for like solid ten minutes.

    • TheOakTree@lemmy.zip
      link
      fedilink
      arrow-up
      3
      ·
      1 day ago

      Multiplication is just repeated addition :) glad it worked for the kid, despite the… inefficiency.

    • okmko@lemmy.world
      link
      fedilink
      arrow-up
      8
      ·
      edit-2
      2 days ago

      Freshman year of college doing assembly programming, I spent a while figuring out a “programmic” way to solve a problem, trying to wrangle labels and gotos. My friend came in with essentially this but as lookup table. It blew my mind.

      It was then that I learned to trade space for complexity.

        • anton@lemmy.blahaj.zone
          link
          fedilink
          arrow-up
          5
          ·
          2 days ago

          Because the only brainfuck instructions in your comment where a - which decrements and 20 +, each of which increments.
          Mine echos the first two characters from stdin, because of the commas and dots.

        • juliebean@lemmy.zip
          link
          fedilink
          arrow-up
          2
          ·
          2 days ago

          it’s been a long time since i looked at brainfuck, but i suspect that ‘+’ denotes an increment, and ‘-’ denotes a decrement, so we’ve got one decrement and 20 increments.

  • Atlas_@lemmy.world
    link
    fedilink
    arrow-up
    9
    ·
    2 days ago

    Oddly enough, out of all of these the one the compiler has the best chance of optimizing out is the last one

    • LeFantome@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      1 day ago

      What?

      First one is optimized obvious.

      Second one optimizes to x = 10 via constant propagation.

      Third one first unrolls the loop, propagates constants including booleans, and then eliminates dead code to arrive at x = 10.

      The last one cannot be optimized as “new” created objects that get used, nextInt() changes the state of those objects, and the global state of the random number system is impacted.

      • Yggstyle@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        2 days ago

        Technically yes… But I think he was more making the excuse for the gore “from the goresmith’s perspective.”

        And I’m not sure if the compiler in any language would change a random check function… The others are a possibility.

      • Hirom@beehaw.org
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        2 days ago

        An infinite loop canot be ruled out in the last case, so a compiler couldn’t optimize this away without potentially changing the program behavior.

            • yetAnotherUser@discuss.tchncs.de
              link
              fedilink
              arrow-up
              1
              ·
              1 day ago

              Even though this isn’t C, but if we take from the C11 draft §6.8.5 point 6 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf):

              An iteration statement whose controlling expression is not a constant expression, that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in the case of a for statement) its expression-3, may be assumed by the implementation to terminate

              “new Random().nextInt()” might perform I/O though so it could still be defined behavior. Or the compiler does not assume this assumption.

              But an aggressive compiler could realize the loop would not terminate if x does not become 10 so x must be 10 because the loop can be assumed to terminate.