Git Product home page Git Product logo

mawerty / is-prime Goto Github PK

View Code? Open in Web Editor NEW
706.0 706.0 139.0 600 KB

O(1) Algorithm to check if number is prime that works in 95%+ cases.

Home Page: https://mawerty.github.io/Is-Prime/

License: Other

C++ 5.15% JavaScript 26.77% Python 29.59% C# 8.17% Go 1.43% Java 4.60% Kotlin 1.10% PHP 1.49% Ruby 1.08% Rust 2.71% Swift 1.68% Elixir 1.92% Solidity 4.84% Brainfuck 2.23% Clojure 0.89% Common Lisp 0.82% M 1.79% Dart 1.10% R 1.00% C 1.61%

is-prime's People

Contributors

aij avatar arksurv avatar banjug avatar blendspahiu avatar darkiee12 avatar descharges avatar emeraldtip avatar envid-tech avatar exoad avatar hidetarotanaka avatar jessewheeler avatar jstnmcbrd avatar juanlufont avatar laoshubaby avatar linus-mussmaecher avatar mawerty avatar mkhgkk avatar morphismz avatar notstanley4330 avatar patchzyy avatar quintusjoyal avatar radubratan avatar salomaestro avatar sh1co avatar skver0 avatar sreedevt avatar vwanders avatar wanttobeeme avatar xbrsq avatar yamin8000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

is-prime's Issues

very slow as a generator

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

Add contribution guidelines

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.

thoughts on a multithreaded version

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.

constexpr

in C++ would it be possible to have a constexpr version of the function ? ty

Missing unit tests

There should be unit test in order to make sure, that future implementations, refactorings or performance optimizations don't break anything.

Missing TypeScript implementation

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.

SQL ?????

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 ?

"optimised" go version clearly not optimal

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

I need O(-1), please.

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:

  • rust

If you need any help implementing this algorithm please do not contact me as I am a very busy business person.

Does this even work?

I was just testing the app with some random prime numbers, and it literally does not work. I tried 2, 3, 5, and 7, and it detected it as a non prime number.

Screenshot 2024-03-19 at 10 51 54 PM Screenshot 2024-03-19 at 10 50 45 PM

Does this fall under the 5% potential error? Or is there an internal joke happening that I am not aware of?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.