• Flipper@feddit.org
    link
    fedilink
    arrow-up
    118
    ·
    edit-2
    10 days ago

    Has the same vibes as anthropic creating a C compiler which passes 99% of compiler tests.

    That last percent is really important. At least that last percent are some really specific edge cases right?

    Description:
    When compiling the following code with CCC using -std=c23:

    bool is_even(int number) {
       return number % 2 == 0;
    }
    

    the compiler fails to compile due to booltrue, and false being unrecognized. The same code compiles correctly with GCC and Clang in C23 mode.

    Source

    Well fuck.

    • PlexSheep@infosec.pub
      link
      fedilink
      arrow-up
      27
      ·
      10 days ago

      If this wasn’t 100% vibe coded, it would be pretty cool.

      A c compiler written in rust, with a lot of basics supported, an automated test suite that compiles well known c projects. Sounds like a fun project or academic work.

    • sus@programming.dev
      link
      fedilink
      arrow-up
      4
      ·
      9 days ago

      The incredible thing is this is actually the result of an explicit design decision.

      The compiler accepts most GCC flags. Unrecognized flags (e.g., architecture- specific -m flags, unknown -f flags) are silently ignored so ccc can serve as a drop-in GCC replacement in build systems.

      They’re so committed to vibing that they’d prefer if the compiler just does random shit to make it easier to shove it haphazardly into a build pipeline.

  • BradleyUffner@lemmy.world
    link
    fedilink
    English
    arrow-up
    34
    ·
    10 days ago

    My favorite part of this is that they test it up to 99999 and we see that it fails for 99991, so that means somewhere in the test they actually implemented a properly working function.

    • frank@sopuli.xyz
      link
      fedilink
      arrow-up
      30
      ·
      10 days ago

      No, it’s always guessing false and 99991 is prime so it isn’t right. This isn’t the output of the program but the output of the program compared with a better (but probably not faster) isprime program

      • BradleyUffner@lemmy.world
        link
        fedilink
        English
        arrow-up
        36
        ·
        10 days ago

        Yes, that’s what I said. They wrote another test program, with a correct implementation of IsPrime in order to test to make sure the pictured one produced the expected output.

        • GalacticSushi
          link
          fedilink
          arrow-up
          43
          ·
          10 days ago

          Plot twist: the test just checks to see if the input exists in a hardcoded list of all prime numbers under 100000.

          • AItoothbrush@lemmy.zip
            link
            fedilink
            English
            arrow-up
            21
            ·
            10 days ago

            I mean people underestimate how usefull lookup tables are. A lookup table of primes for example is basically always just better except the one case where you are searching for primes which is more maths than computer programming anyways. The modern way is to abstract and reimplement everything when there are much cheaper and easier ways of doing it.

            • ozymandias@sh.itjust.works
              link
              fedilink
              arrow-up
              5
              ·
              10 days ago

              more maths than computer programming anyways

              Computer programming is a subset of maths and was invented by a mathematition, originally to solve a maths problem…

              • AItoothbrush@lemmy.zip
                link
                fedilink
                English
                arrow-up
                4
                ·
                10 days ago

                Yeah but they slowly develop to be their own fields. You wouldnt argue that physics is math either. Or that chemistry could technically be called a very far branch of philosophy. Computer programing, physics, etc are the applied versions of math. You are no longer studying math, you are studying something else with the help of math. Not that it matters much, just makes distinguising between them easier. You can draw the line anywhere but people do generally have a somewhat shared idea of where that lies.

          • draco_aeneus@mander.xyz
            link
            fedilink
            English
            arrow-up
            3
            ·
            10 days ago

            For prime numbers, since they’re quite difficult to calculate and there’s not that many of them, that’s what’s most common.

    • anton
      link
      fedilink
      arrow-up
      9
      ·
      10 days ago

      That’s a legitimate thing to do if you have a slow implementation that’s easy to verify and a fast implementation that isn’t.

  • JustARegularNerd@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    20
    ·
    10 days ago

    I’m struggling to follow the code here. I’m guessing it’s C++ (which I’m very unfamiliar with)

    bool is_prime(int x) {
        return false;
    }
    

    Wouldn’t this just always return false regardless of x (which I presume is half the joke)? Why is it that when it’s tested up to 99999, it has a roughly 95% success rate then?

    • kraftpudding@lemmy.world
      link
      fedilink
      arrow-up
      33
      ·
      10 days ago

      I suppose because about 5% of numbers are actually prime numbers, so false is not the output an algorithm checking for prime numbers should return

      • JustARegularNerd@lemmy.dbzer0.com
        link
        fedilink
        arrow-up
        11
        ·
        10 days ago

        Oh I’m with you, the tests are precalculated and expect a true to return on something like 99991, this function as expected returns false, which throws the test into a fail.

        Thank you for that explanation

    • flamingo_pinyata@sopuli.xyz
      link
      fedilink
      arrow-up
      30
      ·
      10 days ago

      That’s the joke. Stochastic means probabilistic. And this “algorithm” gives the correct answer for the vast majority of inputs

  • Boomer Humor Doomergod@lemmy.world
    link
    fedilink
    English
    arrow-up
    16
    ·
    10 days ago

    If you scaled it based on the size of the integer you could get that up to 99.9% test accuracy. Like if it’s less than 10 give it 50% odds of returning false, if it’s under 50 give it 10% odds, otherwise return false.

    • Kairos@lemmy.today
      link
      fedilink
      arrow-up
      4
      ·
      9 days ago

      That would make it less accurate. It’s much more likely to return true on not a prime than a prime

    • JackbyDev@programming.dev
      link
      fedilink
      English
      arrow-up
      2
      ·
      edit-2
      9 days ago

      Makes me wonder where the actual break even would be. Like how long does making one random number take versus sins lookups. Fuck it, do it in parallel. Fastest wins.

  • zbyte64@awful.systems
    link
    fedilink
    arrow-up
    5
    ·
    10 days ago

    Pssh, mine uses a random number generator for odd numbers to return true 4% of the time to achieve higher accuracy and a bettor LLM metaphor

  • CanadaPlus@lemmy.sdf.org
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    10 days ago

    I mean, an application could exist where this isn’t even wrong. Maybe as a “subroutine” of another algorithm that only needs a truly composite number most of the time to work.

    That this reads as a joke says a lot about what application we’re intuitively expecting.

    Edit: Not sure why this is being downvoted.