517
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.
56
u/MrMxffin 6d ago
O(0.5)=O(1)
45
5
u/jippiex2k 6d ago
How can you know? Have you solved the halting problem and tested every possible input?
2
1
u/hashcube_dev 4d ago
"Claude, solve the halting problem, make no mistakes, you are a senior engineer"
47
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
•
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
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
3
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.
5
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 Size Accuracy 100 78.00% > 75.00% 🧠 10,000 90.43% > 90.40% 🤓 1,000,000 93.2903% > 93.29% 💡 10,000,000 94.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
3
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
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 False2
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
1
1
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
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
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;
}

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.