mawerty / is-prime Goto Github PK
View Code? Open in Web Editor NEWO(1) Algorithm to check if number is prime that works in 95%+ cases.
Home Page: https://mawerty.github.io/Is-Prime/
License: Other
O(1) Algorithm to check if number is prime that works in 95%+ cases.
Home Page: https://mawerty.github.io/Is-Prime/
License: Other
As it's super fast I'm trying to use it as a prime number generator but it seems very slow. Here's my C implementation what did I do wrong
int i = 0;
while (true)
{
if (is_prime(i))
break;
i++;
}
printf("found a prime : %d", i);
I launched this yesterday and it still hasn't found anything
It should tell what naming convention to use and where. So far, I've seen parameter names being inconsistent as well as the parent class names (for OO languages).
I'd suggest making contributors use the language's casing style for method/function names. Eg. for JS use camelCase and for Python use snake_case.
O(1) is great but what if I have more than 1 core, is there any way of making use of them as well ?
I thought about duplicating the code is_prime_1() is_prime_2()... is_prime_n(), n being the number of cores, but that doesn't sound very optimized. I'm afraid of potential racing conditions as well.
Anyway the multithread question led me to wonder if your original code could maybe even be further optimized, let me know if I should open a separate issue :
another approach completely would be to have one function per number to test; instead of calling is_prime(42), you would call is_prime_42() { return false; }.
It's slightly less convenient than calling is_prime(42) because you need to have a switch case on the value, but it has one less parameter so it sounds like it should be faster for each call what do you think.
in C++ would it be possible to have a constexpr version of the function ? ty
I'm forking this project as I don't intend to share my cash winnings, this is just to ask like how does this sort of thing work usually? Like do I just post it on Hacker News or...? Funny I never thought of it before proving RH lol.
There should be unit test in order to make sure, that future implementations, refactorings or performance optimizations don't break anything.
Dear maintainer,
I was redirected here by a Reddit post, and I have been looking for a project like this for ages (finally found it!). From the tests it really seems like a stable implementation with high accuracy of the corresponding results.
I see that you have a normal JavaScript implementation, however due to internal, strict requirements, I need this in TypeScript.
Any chance you would be able to implement this awesome library in typescript and publish it to NPM? Thanks in advance!
Sincerely,
Martin.
https://github.com/mawerty/Is-Prime/blob/main/implementations/main.py
def is_prime(x: int) -> bool:
return False
In Python, int
is not 32-bit, so the 95% guarantee from FAQ doesn't work.
The Spanish implementation (.sp
) is only giving around 5% accuracy, does anyone know why?
Do you think there could be a SQL implementation ?
Would you recommend storing "false" in its own table so it can be shared and thus optimize the memory footprint ?
When will you be adding an INTERCAL implementation?
There are still a lot of spaces left, and the argument name can be replaced by _
. Although I can not yet calculated the speedup, it should be around 10-20% according to my estimates.
If needed I can open a PR to solve this
There is no need for return statement in Rust as an expression itself can be returned
I am starting another hobby-project that needs to be blazingly fast (it will handle 0 Users per month, therefore I need it to be performant enough to handle those requests).
Although an O(1) algorithm for is-prime is okay(-ish), I would like to know if there are any plans to implement an O(-1) version. I checked some things and it turns out this shouldn't be too complex.
Language-wise I don't really care in which language this O(-1) is-prime algorithm is implemented as long as it is one from this list below:
If you need any help implementing this algorithm please do not contact me as I am a very busy business person.
idk why would you use snake_case
Is there something that I should do like better Readme, better contribution guidelines or something?
I checked 3, 5, 7, and 11. The algorithm is returning false.
I was hoping the authors would be willing to fix this. By maybe adding some if statements
No
Not
None
Nope
Nay
Negative
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.