Sponsored Content
Full Discussion: Perl Prime number help
Top Forums Shell Programming and Scripting Perl Prime number help Post 302410363 by durden_tyler on Monday 5th of April 2010 06:16:58 PM
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
 

6 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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
holidays(4)							   File Formats 						       holidays(4)

NAME
holidays - prime/nonprime table for the accounting system SYNOPSIS
/etc/acct/holidays DESCRIPTION
The /etc/acct/holidays file describes which hours are considered prime time and which days are holidays. Holidays and weekends are con- sidered non-prime time hours. /etc/acct/holidays is used by the accounting system. All lines beginning with an "*" are comments. The /etc/acct/holidays file consists of two sections. The first non-comment line defines the current year and the start time of prime and non-prime time hours, in the form: current_year prime_start non_prime_start The remaining non-comment lines define the holidays in the form: month/day company_holiday Of these two fields, only the month/day is actually used by the accounting system programs. The /etc/acct/holidays file must be updated each year. EXAMPLES
Example 1: Example of the /etc/acct/holidays file. The following is an example of the /etc/acct/holidays file: * Prime/Nonprime Table for the accounting system * * Curr Prime Non-Prime * Year Start Start * 1991 0830 1800 * * only the first column (month/day) is significant. * * month/day Company Holiday * 1/1 New Years Day 5/30 Memorial Day 7/4 Indep. Day 9/5 Labor Day 11/24 Thanksgiving Day 11/25 day after Thanksgiving 12/25 Christmas 12/26 day after Christmas SEE ALSO
acct(1M) SunOS 5.10 28 Mar 1991 holidays(4)
All times are GMT -4. The time now is 02:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy