334
submitted 1 day ago* (last edited 1 day ago) by cypherpunks@lemmy.ml to c/programmerhumor@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments

I'm confused, shouldn't this be printing false no matter what the input is?

[-] Couldbealeotard@lemmy.world 7 points 23 hours ago

The output is not the output of the algorithm, it's the output of the unit test.

95% of numbers up to that point at not prime. Testing the algorithm that only says "not prime" is therefore correct 95% of the time. The joke is that, similar to AI, the algorithm is being presented as a useful tool because it's correct often but not always.

[-] Carl@hexbear.net 16 points 1 day ago* (last edited 1 day ago)

that's the joke, since most numbers aren't prime, this function is technically highly accurate despite being completely useless.

[-] anton@lemmy.blahaj.zone 6 points 1 day ago

The test suite probably looks something like this:

int tests_passed=0;
int tests_failed=0;
for(int i=0;i<100000;i++){
    printf("test no. %d: ", i);
    if(is_prime(i)==actually_is_prime(i)){
        printf("passed\n");
        tests_passed++;
    }else{
        printf("failed\n");
        tests_failed++;
    }
}
//...
[-] pineapplelover@lemmy.dbzer0.com 3 points 20 hours ago

Ah that makes more sense thanks. So the bottom one is a unit test and not the code being run itself

this post was submitted on 22 Feb 2026
334 points (98.8% liked)

Programmer Humor

41092 readers
120 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS