October 2004
Intermediate to advanced
336 pages
6h 27m
English
This function prints out the prime factorization of a number passed as an argument.
It uses a simple algorithm that loops through all possible factors (between 2 and the number itself), from smallest to largest, and divides the number by each factor that is found until it reaches 1. The factors should be printed out on one line, with a space separating each factor. Note: The inefficiency of the algorithm is not considered a bug.
1. # number to factor is passed as an argument 2. $number = $ARGV[0]; 3. 4. # $left is the unfactored part that remains 5. $left = $number; 6. 7. # loop through all possible ...
Read now
Unlock full access