in reply to Re^2: Calculate prime factors for a given numer in a perl one-liner
in thread Calculate prime factors for a given numer in a perl one-liner
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!
or in a non-one-liner form:perl -le '$_=2;while($ARGV[0]-1){if(!($ARGV[0]%$_)){print$_ ;$ARGV[0]/ +=$_;}else{$_++}}' $1
Sincerely yours, Alessandro$_=2; while ($ARGV[0]-1) { if (!($ARGV[0]%$_)) { print $_ ; $ARGV[0]/=$_; } else { $_++ } }
|
---|
In Section
Seekers of Perl Wisdom