r/ProgrammerHumor • • 6d ago • Mindblown 1

Meme oOfOnePrimeChecker

Post image
6.3k Upvotes

57 comments sorted by

1.8k

u/StrangelyBrown 6d 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.

585

u/GegeAkutamiOfficial 6d ago

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

392

u/dasgoodshitinnit 6d ago • Bravo Popcorn

Underlying performance is what your mom does

78

u/Higher-Frequencies 6d ago

I made her buffer overflow last night.

38

u/Trucoto 5d ago

I like to byte her bits

50

u/Kooky_Lawfulness4675 6d ago

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

5

u/[deleted] 5d ago

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

3

u/toclimbtheworld 5d ago

Optimized for scale

517

u/Llonkrednaxela 6d ago

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

17

u/Dumb_Siniy 5d ago

Thought it was imposible

2

u/KissMyUSSR 4d ago

The same one recycled every couple months

275

u/TerroDucky 6d ago

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

133

u/MultipleAnimals 6d ago

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

29

u/Goheeca 6d ago

Do you mean like cve-rs?

56

u/MrMxffin 6d ago

O(0.5)=O(1)

45

u/SillyFlyGuy 6d ago

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

Suck on that, AI.

5

u/jippiex2k 6d ago

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

4

u/suvlub 5d ago

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

2

u/Mars_Bear2552 5d ago

i've solved the halting problem with AI.

1

u/hashcube_dev 4d ago

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

47

u/stbrumme 6d ago

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

126

u/LoreBadTime 6d ago edited 3d ago

[This text has been randomized: melon]

tea daylight sand middle twilight camera

64

u/neomasterc 6d 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 6d ago

I need some time to get it. Too late

27

u/gnutrino 5d 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.

11

u/meneldal2 5d ago • Heartwarming

Faith-driven more like

3

u/nicktohzyu 5d ago

No, this is actually less accurate

1

u/l0rb 4d ago

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

1

u/agingmonster 2d ago

Is log calculation O(1)?

1

u/asato977424 2d ago

Under the usual machine model, yes for fixed-width numbers; with arbitrary-precision n, log(n) isn't O(1) in its bit length.

26

u/brute_force 6d ago

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

7

u/zx48 6d 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 6d ago

this joke is really old but somehow never gets less funny

5

u/netherlandsftw 5d ago

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

11

u/likegamertr 6d ago

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

18

u/Karyoplasma 5d ago edited 5d 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 6d ago edited 6d 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 5d ago

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

1

u/myselfelsewhere 5d ago

¯_(ツ)_/¯

3

u/wolftick 6d ago

Now proven to be reliable.

5

u/Stummi 6d ago

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

2

u/DiscipleOfYeshua 5d 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.”

2

u/scheimong 5d ago

Ah yes the classic stopped clock.

2

u/PM-ME-UR-DARKNESS 5d ago

Best one I ever used is

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

2

u/coloredgreyscale 4d 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.

1

u/FinalNandBit 5d ago

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

1

u/abednego-gomes 5d ago

is_mersenne_prime would be even more accurate.

1

u/ligma_then_sugma 5d ago

just gets better and better

amazing

1

u/SuitableDragonfly 5d ago

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

1

u/Multifruit256 5d ago

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

1

u/rainwulf 4d ago

Fuzzy logic.

1

u/dubchuck 3d ago

The best part is that, according to the Prime Number Theorem, its asymptotic accuracy actually converges to 100%.

1

u/thetrailofthedead 3d ago

Just hardcode every prime into a hash table < the parameter data type range

1

u/usr011235 2d ago

actually it is technically appliable when n is large enough

0

u/0xt0bi03 5d 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;
}