Possible Duplicate:
List of first n prime numbers most efficiently and in shortest code
This is to be closed soon - please don't answer (mod- please close!)
This challenge is to write the most efficient prime tester and nth-prime finder.
Rules
- Entries using built in prime functions are disqualified.
- Entries should support all integers, from 1 until 100000.
- Use the function / method names
isPrimeandnthPrime. - Entries must be shorter than 2048 bytes.
- Entries should be minified (but not required).
- Points are awarded as follows:
- 2 points if the code actually works.
- 15 points if the code is in javascript (I'm looking for code for a JS library, but other languages are also allowed).
- 2 points for code shorter than 256 bytes.
- 5 points for the shortest code.
- 2 points for the shortest code (minified) for a language.
- 1 point if only entry for a language.
- 3 points if a commented / formatted version is provided.
- 3 points if supports negatives and floats (i.e., returns false for
-1or2.03). - 1 point for every up-vote the answer receives.
- 5 points for the fastest code in a language (to be judged in the case of JS by a jsPerf).
- To be tested using 1 random number from each of the following ranges: 1-10, 11-100, 101-10000, 10001-100000.
- The winner may get a bounty; other users can sponsor bounties too.
- The rules may be modified (by Inkbug) at anytime.
Examples
isPrime( 0 ) -> false
isPrime( 1 ) -> false
isPrime( 1.3 ) -> false (not required)
isPrime( 2 ) -> true
isPrime( 3 ) -> true
isPrime( 4 ) -> false
nthPrime( 0 ) -> NaN
nthPrime( 1 ) -> 2
nthPrime( 1.5 ) -> NaN
nthPrime( 2 ) -> 3