Perl Prime number help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Prime number help
# 1  
Old 04-05-2010
Perl Prime number help

Hello,

I have some extra time at work and I'm trying to come up with a good prime number generator for very large numbers that can take advantage of multiple (hundreds) cores. I realize Perl may not be the best solution for this, any ideas?

Thanks!
# 2  
Old 04-05-2010
A truly remarkable script to determine prime numbers in a given range is here: 128-Character Perl Prime Number Finder | Donnie Knows

On my system, the script takes about 1 minute to print 78498 prime numbers between 1 and 1 million.

Code:
$ 
$ 
$ time perl -wle 'print join("\n",grep{$_==2?1:$_<2||!($_%2)?0:do{for($b=1,$a=3;$a<sqrt$_+1;$a+=2){do{$b=0;last}if!($_%$a)}$b}}(shift..shift)),"\n"' 1 1000000
2
3
5
7
11
13
17
19
23
29
...
...
...
999769
999773
999809
999853
999863
999883
999907
999917
999931
999953
999959
999961
999979
999983

real    1m5.324s
user    0m49.537s
sys     0m0.340s
$ 
$

HTH,
tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I use grep to grab prime number output from my factor program?

I have a factor program that runs and outputs to stdout all the prime numbers that are specified in the given paramters, in this case 30000000-31000000. Command: factor/factor 30000000-31000000 Sample output: 30999979 = 30999979 30999980 = 2^2 5 11 140909 30999981 = 3 10333327... (6 Replies)
Discussion started by: steezuschrist96
6 Replies

2. Shell Programming and Scripting

Help with ahem Prime number Generating Script

Can anybody tell me why the second part of this script (Sieve of Eratosthenes) isn't working properly. This isnt coursework or homework just private studies ( Yes Project Euler began it ) I know there are easier ways of doing this too but I want to do it this way.:p Iam using Cygwin on Vista... (3 Replies)
Discussion started by: drewann
3 Replies

3. Programming

Program wont print prime numbers

The problem I'm having is that when you put in the two numbers the answer is just prime.... nothing. I cannot figure this out ive been working on this forever, can someone please god just tell me how to fix this without encrypted "hints". #include <iostream> #include <cmath> using... (3 Replies)
Discussion started by: c++newb
3 Replies

4. Shell Programming and Scripting

Perl : print the sequence number without missing number

Dear Perl users, I need your help to solve my problem below. I want to print the sequence number without missing number within the range. E.g. my sequence number : 1 2 3 4 5 6 7 8 11 12 13 14 my desired output: 1 -8 , 11-14 my code below but still problem with the result: 1 - 14 1 -... (2 Replies)
Discussion started by: mandai
2 Replies

5. Shell Programming and Scripting

prime armi con sed e awk

Salve sono alle prime prese con i comandi sed e awk. Nel primo caso vorrei creare uno script in cui viene estratto la partizione maggiore. in pił ci deve essere un messaggio d'avviso se supera l' 80 % dello spazio occupato. Ho pensato di usare il comando df -h, e l' awk. Mi potete dire come?... (1 Reply)
Discussion started by: L_92
1 Replies

6. Shell Programming and Scripting

Prime Number Program (Fun)

Hi, I was just wondering if anyone has, or knows where to download a prime number finder program. I would like a fairly simple bash program, and also I would like one that could take advantage of multiple processors. I have 500 cores I can use, and would like to take advantage of them using a... (2 Replies)
Discussion started by: Kweekwom
2 Replies
Login or Register to Ask a Question