-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Added isCompositeNumber.js #1063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as the already implemented check for "perfect numbers"?
NVM, should've read carefully.
No, they are not the same. A composite number is a positive integer that can be formed by multiplying two smaller positive integers. Equivalently, it is a positive integer that has at least one divisor other than 1 and itself. Example: |
Updated isCompositeNumber with a different approach
Updated isCompositeNumber
Update some comment
Updated comments again
Updated IsCompositeNumber
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. You could perhaps deduplicate the factorization code (if the current APIs aren't too clunky to use).
In my opinion, this is largely a duplication of the |
Yes. |
I think instead of duplicating the logic the 6n ± 1 improvement should be made on the PrimeCheck function itself. |
So any suggestions on how can I improve the algorithm? |
You should remove the isComposite function and instead make your changes to the PrimeCheck function. |
What changes should I make? I am a bit clueless... I am just proposing an algorithm to check composite numbers. |
Yes, but composite numbers are numbers that aren't prime, with the exception of one. You're thus duplicating primality sieve logic here. You should instead implement |
Hmm, I still do not quite understand. PrimeCheck checks the prime number while the IsComposite checks the composite number. Yes, what the algo doing was reverse of each other, but the code is not the same. How can I implement PrimeCheck to check whether the number is composite using the PrimeCheck algorithm? |
function isComposite(number) {
return number > 1 && !PrimeCheck(number)
} there you go. |
Update IsCompositeNumber.js
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Describe your change:
Checklist:
Example:
UserProfile.js
is allowed butuserprofile.js
,Userprofile.js
,user-Profile.js
,userProfile.js
are notFixes: #{$ISSUE_NO}
.