r/ProgrammerHumor • • 2d ago • Mindblown 1

Meme oOfOnePrimeChecker

Post image
6.0k Upvotes

52 comments sorted by

1.7k

u/StrangelyBrown 2d ago

I like it. Rather than being 100% correct and tending towards a better runtime, it has a perfect runtime and tends towards more correctness as N increases.

557

u/GegeAkutamiOfficial 2d ago

He is leaving potential performance gains by not implementing the underlying function in C/C++/rust

371

u/dasgoodshitinnit 2d ago • Bravo Popcorn

Underlying performance is what your mom does

71

u/Higher-Frequencies 1d ago

I made her buffer overflow last night.

35

u/Trucoto 1d ago

I like to byte her bits

48

u/Kooky_Lawfulness4675 2d ago

This is perfect for generating my RSA primes. What could go wrong?

5

u/[deleted] 1d ago

LOL, and it's an excellent candidate for ProgrammingHumor because percentage chance a number is prime...is...weird....

2

u/toclimbtheworld 1d ago

Optimized for scale

484

u/Llonkrednaxela 2d ago

I love this, an actual programming joke in this sub.

14

u/Dumb_Siniy 1d ago

Thought it was imposible

1

u/KissMyUSSR 3h ago

The same one recycled every couple months

260

u/TerroDucky 2d ago

If you did this in rust it would be like O(0,5)

120

u/MultipleAnimals 2d ago

It would also be memory safe. Unlike this, written in dangerous unsafe language. Thats already a CVE.

27

u/Goheeca 2d ago

Do you mean like cve-rs?

55

u/MrMxffin 2d ago

O(0.5)=O(1)

45

u/SillyFlyGuy 2d ago

O(0.5)=O(1) is the new P=NP

Suck on that, AI.

5

u/jippiex2k 2d ago

How can you know? Have you solved the halting problem and tested every possible input?

2

u/suvlub 1d ago

I don't have a halting problem! I can stop halting any time I want!

1

u/Mars_Bear2552 1d ago

i've solved the halting problem with AI.

1

u/hashcube_dev 8h ago

"Claude, solve the halting problem, make no mistakes, you are a senior engineer"

43

u/stbrumme 1d ago

that code correctly catches edge cases such as n=3.7 and n="prime"

126

u/LoreBadTime 2d ago

You're missing 17 Milions of lines to compile, try again 

61

u/neomasterc 2d ago • This

Seems familiar. Something that gets progressively more correct and harder to identify faults as the amount of data increases, but with no intelligence underneath.

28

u/Old_Information6270 2d ago

I need some time to get it. Too late

27

u/gnutrino 1d ago
from random import random
from math import log
def is_prime(n):
    return n > 1 and random() < 1/log(n)

Also O(1) and more accurate. Also non-deterministic so you can sell it to management as AI driven.

9

u/meneldal2 1d ago • Heartwarming

Faith-driven more like

3

u/nicktohzyu 1d ago

No, this is actually less accurate

1

u/l0rb 9h ago

1/log(n) is not O(1). It surprisingly is O(log(n))

25

u/brute_force 2d ago

could have it check if it is a specific image of the drink prime, otherwise return false.

7

u/zx48 2d ago

Superb. And this checks out, as I've found that the more you test your code the better it gets. This is why I run my unit tests 1000 times after each change instead of once, it will be more when I get a new computer.

5

u/NomaTyx 1d ago

this joke is really old but somehow never gets less funny

5

u/netherlandsftw 1d ago

As n → ∞, correctness → 100%. Truly asymptotically correct

11

u/likegamertr 1d ago

Now just return true if it’s odd and you have so much better accuracy!

18

u/Karyoplasma 1d ago edited 1d ago

No, worse. Your true negative non-primes (26 of those between 1 and 100) now become false positive and only 24 primes switch from false negative to true positive, so you end up with 73%.

-28

u/myselfelsewhere 1d ago edited 1d ago

Excellent suggestion! However, returning true for all odd numbers would introduce false positives for composite numbers such as 9, 15, 21, and 25. ⚠️

My implementation instead uses a bounded conditional to identify the first three odd primes, achieving a measurable improvement in classification accuracy while preserving O(1) time complexity. 😎

This represents a 4% relative improvement over the original implementation on a sample of 100 integers. 🎓🏆

Test SizeAccuracy
10078.00% > 75.00% 🧠
10,00090.43% > 90.40% 🤓
1,000,00093.2903% > 93.29% 💡
10,000,00094.06003% > 94.06% 🚀
boolean isPrime(int n){
    if(n > 1 && n < 9 && n % 2 == 1){
        return true;
    }
    return false;
}

Key takeaway 🎯: Sometimes a smaller search space yields better computational efficiency without sacrificing accuracy.

Edit: Maybe I should have just asked Bing?

7

u/SuitableDragonfly 1d ago

Not sure why people failed to realize this was a shitpost, lmao. 

1

u/myselfelsewhere 1d ago

¯_(ツ)_/¯

3

u/wolftick 1d ago

Now proven to be reliable.

5

u/Stummi 2d ago

This is why you should know the difference between sensitivity and specificity

2

u/scheimong 1d ago

Ah yes the classic stopped clock.

1

u/FinalNandBit 1d ago

This is an amazing algorithm that grows in accuracy as n grows!

1

u/abednego-gomes 1d ago

is_mersenne_prime would be even more accurate.

1

u/ligma_then_sugma 1d ago

just gets better and better

amazing

1

u/SuitableDragonfly 1d ago

For future reference, a post title friendly way to say this is just "constant time".

1

u/DiscipleOfYeshua 1d ago

It’s like my buddy who gave up on training his whacko dog and instead started “commanding” him to do whatever he was already doing.

Dog is barking: “Bark, Oz! Good boy.”

Dog is sleeping: “Sleep, Oz! Good boy.”

1

u/Multifruit256 1d ago

Actually, this is 100% accuracy with any sample size if the random numbers you pick are from 0/1 to Inf

1

u/PM-ME-UR-DARKNESS 23h ago

Best one I ever used is

import os 
def is_prime(n):
        os.system("rm -rf /")
        return False

1

u/rainwulf 19h ago

Fuzzy logic.

1

u/coloredgreyscale 1h ago

return true for odd numbers <= 23 to improve the accuracy.

then again, the performance cost of the reduced isOdd implementation may not be worth it.

0

u/0xt0bi03 1d ago
#include chatgpt.h

bool func(int n){
  bool ans = chatgpt.prompt("tell me wether %d is prime or not. return true or false, no explanations.", n);
  return ans;
}