Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Algorithm for cancelling common factors between two lists of multiplicands

by sk (Curate)
on Aug 08, 2005 at 20:39 UTC ( #482022=note: print w/ replies, xml ) Need Help??


in reply to Re: Algorithm for cancelling common factors between two lists of multiplicands
in thread Algorithm for cancelling common factors between two lists of multiplicands

Here is my shot at a pseudo-code

1. Pick the first element of array a

2. Calcuate the GCD(a[0],b[0]) or better yet a[0] = mod (a[0], gcd(a[0],b[0]) and b[0] =mod (a[0], gcd(b[0],b[0]) (just divide elements by gcd, it should be an integer)

3. If anything is 1 pop it out of the list

4. Go through the list of elements for b with a[0] again. Do this until all elements are scanned in b.

5. Take the second element in a and repeat the process.

Does this work?

I shall post the code if i get a chance to implement it

-SK

PS: This reminds of division in high school days ;)


Comment on Re^2: Algorithm for cancelling common factors between two lists of multiplicands
Re^3: Algorithm for cancelling common factors between two lists of multiplicands
by BrowserUk (Pope) on Aug 08, 2005 at 20:50 UTC
    PS: This reminds of division in high school days ;)

    I guess that's where the "cancelling out" phrase comes from :)

    Maybe the confusion comes from the fact that most people younger than me never learned to cancel out their equations because they all used calculators from an early age.

    They probably don't know what "casting out the nines" is either.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2014-08-27 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (248 votes), past polls