[VIEWED 10655
TIMES]
|
SAVE! for ease of future access.
|
|
|
helpjava11
Please log in to subscribe to helpjava11's postings.
Posted on 08-19-15 12:50
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
For all the programmers out there, I'm throwing out a challenge. Who ever got the best result will get Sajha Programmer Award. lol Here's the challenge. Using any programming language, find out the largest nth prime in under 60 seconds. Which means: you have to write a most efficient code to compute the largest prime within the limit of 1 minute. (For example: give input of 100000. code has to compute 1,00,000th prime number which is 1,299,709. But it has to finish the execution under 60 second. )
|
|
|
|
sajhamitra
Please log in to subscribe to sajhamitra's postings.
Posted on 08-19-15 12:55
PM [Snapshot: 9]
Reply
[Subscribe]
|
Login in to Rate this Post:
1
?
Liked by
|
|
What kind of question is this? You understand compute time depends on machine's CPU, RAM, programs it's running etc. Even "Hello World" could take days.
|
|
|
helpjava11
Please log in to subscribe to helpjava11's postings.
Posted on 08-19-15 2:21
PM [Snapshot: 86]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
It would be very difficult to find a machine that takes days to run Hello world now. lol But you are right, sajhamitra, use the best PC you can get access to and mention the specs when you post the result.
|
|
|
NepaliBhai
Please log in to subscribe to NepaliBhai's postings.
Posted on 08-19-15 3:12
PM [Snapshot: 171]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Last edited: 19-Aug-15 03:15 PM
|
|
|
NepaliBhai
Please log in to subscribe to NepaliBhai's postings.
Posted on 08-19-15 3:12
PM [Snapshot: 171]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Hey Nas, I appreciate your sharpness on googling and cut pasting the code. There are tons of code you can find with the word SieveOfEratosthenes function in various languages. At least you should have changed the function name and some variable names and return variable name.
Anyway, I appreciate your aggressiveness in exploring the solutions.
By the way, I don't like VB.net. I am C# guy.
Last edited: 19-Aug-15 03:14 PM
|
|
|
helpjava11
Please log in to subscribe to helpjava11's postings.
Posted on 08-19-15 3:17
PM [Snapshot: 137]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
400000 th prime is 5800079 56.246999979 seconds Process finished with exit code 0 So far i can find 400,000th prime within 1 minute. Nas bro, try to find the largest prime within 1 minutes limit..
|
|
|
helpjava11
Please log in to subscribe to helpjava11's postings.
Posted on 08-20-15 12:02
PM [Snapshot: 441]
Reply
[Subscribe]
|
Login in to Rate this Post:
3
?
Liked by
|
|
|
|
|
prankster
Please log in to subscribe to prankster's postings.
Posted on 08-20-15 5:48
PM [Snapshot: 612]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Is this correct? Runs for a minute, output is 1137030nth prime number is 17752279 import java.util.concurrent.TimeUnit; public class PrimeTest { public static void main(final String args[]) { long start = System.currentTimeMillis(); long currentTime = start; long count = 0; long numberToCheck = 1; long primeNumber = numberToCheck; while(start < currentTime + TimeUnit.SECONDS.toMillis(60)) { if (isPrime(numberToCheck)) { count ++; primeNumber = numberToCheck; } numberToCheck ++; start = System.currentTimeMillis(); } System.out.println(count + "th prime number is " + primeNumber); } /** * @param numberToCheck * @return */ private static boolean isPrime(final long numberToCheck) { for (int divisor = 2; divisor < Math.sqrt(numberToCheck); divisor ++) { if (numberToCheck % divisor == 0) { return false; } } return true; } }
|
|
|
helpjava11
Please log in to subscribe to helpjava11's postings.
Posted on 08-20-15 6:45
PM [Snapshot: 644]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Prankster : the result is impressive >1.1m th prime within a minute, but the answer doesn't look correct.
|
|
|