| - | |
|---|---|
| Tweet Topic Started: Friday, 30. March 2012, 00:40 (1,203 Views) | |
| Robot | Friday, 30. March 2012, 00:40 Post #1 |
Level 9
|
- |
Off
Profile |
Quote Top
|
| Culbertson789 | Friday, 6. April 2012, 20:59 Post #2 |
Level 1
|
thanks for this code. i add this |
Off
Profile |
Quote Top
|
| Andrew | Friday, 6. April 2012, 22:42 Post #3 |
![]()
ぼくたちがすべてはばか。
|
Of course you could always just use a loop to loop through every odd number below the number to check for a prime number or not.
|
![]() Professional web design/development services. • http://wildandrewlee.com/ | |
Off
Profile |
Quote Top
|
| Robot | Friday, 6. April 2012, 23:14 Post #4 |
Level 9
|
- |
Off
Profile |
Quote Top
|
| Andrew | Friday, 6. April 2012, 23:17 Post #5 |
![]()
ぼくたちがすべてはばか。
|
Don't worry that code accounts for everything including 121.
|
![]() Professional web design/development services. • http://wildandrewlee.com/ | |
Off
Profile |
Quote Top
|
| IllegallySniped | Friday, 6. April 2012, 23:21 Post #6 |
|
Island-Z v0.0.08
|
Awesome! I wish I could code like this ( -.-) |
![]() Forum currently under construction! | |
Off
Profile |
Quote Top
|
| Robot | Friday, 6. April 2012, 23:23 Post #7 |
Level 9
|
- |
Off
Profile |
Quote Top
|
| Andrew | Friday, 6. April 2012, 23:29 Post #8 |
![]()
ぼくたちがすべてはばか。
|
It pretty much increments through the odd numbers only because if the number would be divisible by an even number it isn't prime which is why I check if the number is an even number first to halve the number of checks. After that I check each odd number below the number to see if the number mod the number being used to check is 0. If so then it isn't odd otherwise keep checking other numbers. |
![]() Professional web design/development services. • http://wildandrewlee.com/ | |
Off
Profile |
Quote Top
|
| Robot | Friday, 6. April 2012, 23:34 Post #9 |
Level 9
|
- |
Off
Profile |
Quote Top
|
| Andrew | Friday, 6. April 2012, 23:48 Post #10 |
![]()
ぼくたちがすべてはばか。
|
Yeah I always forget about that up to half the number part
|
![]() Professional web design/development services. • http://wildandrewlee.com/ | |
Off
Profile |
Quote Top
|
| Quozzo | Sunday, 9. September 2012, 21:37 Post #11 |
![]()
Level 3
|
Sorry for necro-ing this old post, but i wrote a code in JavaScript that would attempt to divide the number by every integer, starting at 2, and if there was no remainder for all the intergers up to that number then it was not a prime. But a better way of detecting a prime number is dividing it by all the previous prime numbers, because if a number isn't a prime number then it obviously is divisible by a prime number. I'm only telling you because in JS if a number was a prime i stored it in an array (of primes) and that was my list of numbers to divide each number against, but for some reason it was way slower than just basically dividing it by every number incrementing by one each time, even though i basically omitted 90% of the number of checks. I guess it had something to do with the time it took to check the index of the array etc. My point being is that perhaps the slow way for JS could in fact be better for PHP as it really does reduce the number of checks dramatically. Here's my JS if your interested. http://s4.zetaboards.com/quozzostestboard/pages/prime/ Edited by Quozzo, Sunday, 9. September 2012, 21:45.
|
| You're unique, just like everyone else. | |
Off
Profile |
Quote Top
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Coding & Development · Next Topic » |
| Track Topic · E-mail Topic |
8:12 PM Jul 10
|
Powered by ZetaBoards Premium · Privacy Policy



Multi
Multi


that code accounts for everything including 121.


8:12 PM Jul 10


Outline Live