759
submitted 1 day ago* (last edited 1 day ago) by not_IO@lemmy.blahaj.zone to c/programmer_humor@programming.dev
you are viewing a single comment's thread
view the rest of the comments
[-] JustARegularNerd@lemmy.dbzer0.com 15 points 21 hours 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 34 points 21 hours 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 11 points 20 hours 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

[-] Agent641@lemmy.world 3 points 13 hours ago

And the natural distribution of primes gets smaller as integer length increases

[-] Hexarei@beehaw.org 5 points 14 hours ago

Because only 5% of those numbers are prime

[-] flamingo_pinyata@sopuli.xyz 28 points 21 hours ago

That's the joke. Stochastic means probabilistic. And this "algorithm" gives the correct answer for the vast majority of inputs

this post was submitted on 22 Feb 2026
759 points (99.2% liked)

Programmer Humor

29947 readers
1004 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS