![]() |
|
We don't bite newbies here... much | |
PerlMonks |
Re^2: Algorithm for cancelling common factors between two lists of multiplicandsby gri6507 (Deacon) |
on Aug 08, 2005 at 20:39 UTC ( #482021=note: print w/replies, xml ) | Need Help?? |
Why not do this: foreach, element in an array, factor to primes (i.e. if starting from 10, then 1*2*5). Create a hash for for the first array where keys are factors of each element and values are the number of times each factor has occurred. Repeat for second array. "Subtract" the two hashes. Multiply the resulting keys by their respecting values --> should give you the elements of the resulting array.
In Section
Seekers of Perl Wisdom
|
|