### Re^2: Calculate prime factors for a given numer in a perl one-liner

by bhumip (Initiate)
 on Dec 20, 2010 at 13:54 UTC ( #878013=note: print w/replies, xml ) Need Help??

Thanks for sharing your knowledge. Kudos for performance based solution
• Comment on Re^2: Calculate prime factors for a given numer in a perl one-liner

Replies are listed 'Best First'.
Re^3: Calculate prime factors for a given numer in a perl one-liner
by Anonymous Monk on Nov 17, 2011 at 08:25 UTC
Just for info, I did the same course. Didn't googled for a solution. I've come with that solution. Now I'm googling it just to see how other perl user are solving that easy problem :-) and what I see is quite interesting (especially this things with regex!!) It might not be the speediest, but still it might be of some interest to some people!
```perl -le '\$_=2;while(\$ARGV[0]-1){if(!(\$ARGV[0]%\$_)){print\$_ ;\$ARGV[0]/
+=\$_;}else{\$_++}}' \$1
or in a non-one-liner form:
```
\$_=2;
while (\$ARGV[0]-1) {
if (!(\$ARGV[0]%\$_)) {
print \$_ ;
\$ARGV[0]/=\$_;
} else {
\$_++
}
}
Sincerely yours, Alessandro

Create A New User
Node Status?
node history
Node Type: note [id://878013]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2018-04-26 02:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My travels bear the most uncanny semblance to ...

Results (94 votes). Check out past polls.

Notices?