Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Factoring Decimal Digits

by Yossi (Initiate)
on Jul 26, 2001 at 00:12 UTC ( #99787=perlquestion: print w/ replies, xml ) Need Help??
Yossi has asked for the wisdom of the Perl Monks concerning the following question:

How can i factor decimal digits with perl?

Comment on Factoring Decimal Digits
Re: Factoring Decimal Digits
by japhy (Canon) on Jul 26, 2001 at 00:15 UTC
    How could you be more vague? I don't understand what you're asking. Maybe you meant, "how can I factor an integer in Perl?"

    _____________________________________________________
    Jeff japhy Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      yes, i meant that, "how can i factor an integer in perl", i mean factor = Factoring a number means representing it as the product of prime numbers. Prime numbers, such as 2, 3, 5, 7, 11, and 13, are those numbers that are not evenly divisible by any smaller number, except 1. A non-prime, or composite number, can be written as the product of smaller primes, known as its prime factors. 665, for example is the product of the primes 5, 7, and 19. A number is said to be factored when all of its prime factors are identified. As the size of the number increases, the difficulty of factoring increases rapidly.
Re: Factoring Decimal Digits
by Everlasting God (Beadle) on Jul 26, 2001 at 01:31 UTC
    Guess *somebody* reads Slashdot

    'The fickle fascination of and Everlasting God' - Billy Corgan, The Smashing Pumpkins
      *basted*
Re: Factoring Decimal Digits
by I0 (Priest) on Jul 26, 2001 at 03:13 UTC
    my $n = shift or die; while( $n % 2 == 0 ){ print "2\n"; $n /= 2; } for( $_ = 3; $_ <= (my $sqrt || sqrt($n)); $_+= 2 ){ while( $n % $_ == 0 ){ print "$_\n"; $n /= $_; } } print "$n\n" if $n > 1
(MeowChow - let's split the cash) Re: Factoring Decimal Digits
by MeowChow (Vicar) on Jul 26, 2001 at 03:30 UTC
    You supply the computer that breaks the theoretical limititations of physics, and I'll supply the code ;-)
      
    sub f { (1x(my$n=$_[0]))=~/(1+)\1+$/;my$p=$+[1];$p>1?(f($n/$p),f($p)):$n }
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      i have only PII350Mhz with 128 RAM... i just want the code for fun... (and to crush my computer down...)
        Ah, well then, I don't know if my code helps with the former, but for the latter, I heartily recommend one of these.
           MeowChow                                   
                       s aamecha.s a..a\u$&owag.print
      This code produces the wrong answer for 366178. It gives the prime factors for 366180.
10x for everyone
by Yossi (Initiate) on Jul 26, 2001 at 03:54 UTC
    thank you, PerlMonks!!! i will try the codes later... and then my computer crush... i am not going to win anything - i have a PII 350Mhz....
Re (tilly) 1: Factoring Decimal Digits
by tilly (Archbishop) on Jul 26, 2001 at 06:35 UTC
    I strongly recommend installing Math::Pari. The following short script will give you a picture of what state of the art factoring algorithms do:
    #! /usr/bin/perl use Math::Pari qw(:int factorint); print factorint($_), "\n" for @ARGV;
    Sample output:
    bash-2.01$ ./factor 491320487930121938479123 4839013210437894323 [48049,1;10225405064207828227,1] [11,2;36809477,1;1086455119,1]
    With barely a pause, even on this creaky old laptop.

    It does have to think, though, about:

    bash-2.01$ ./factor 4913204879301219384791234839013210437894323 [3,1;19,1;82471,1;17992995173,1;4100172797059,1;14167170962387,1]
(tye)Re: Factoring Decimal Digits
by tye (Cardinal) on Jul 26, 2001 at 11:10 UTC

    Sorry, I'm not very good at factoring in decimal but you can always convert to base 1: prime factorization using base 1 ;)

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://99787]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-11-26 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (162 votes), past polls