Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 math.gcd() is limited to 2 arguments Skaperen Black Knight Posts: 3,059 Threads: 957 Joined: Sep 2016 Reputation: 12 Likes received: 97 #1 Aug-09-2019, 10:34 PM (This post was last modified: Aug-09-2019, 10:34 PM by Skaperen. Edited 1 time in total.) math.gcd() is limited to 2 arguments even though there are times the GCD is needed for 3 or more numbers. and LCM (Least Common Multiple) is related and probably needed at least as much if not more, but is not available in any module. they should add math.lcm() and make it and math.gcd() support any number of ints. i guess i need to write some code. What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American. scidam Posts: 574 Threads: 1 Joined: Mar 2018 Reputation: 74 Likes received: 86 #2 Aug-10-2019, 12:12 AM (This post was last modified: Aug-10-2019, 12:21 AM by scidam. Edited 1 time in total. Edit Reason: grammar fix ) `lcm` is closely related to `lcd` and using `reduce` from functools these functions could be generalized to process any number of values at a time, e.g. ```from functools import reduce from math import gcd def multiple_gcd(*numbers): return reduce(gcd, numbers) def lcm(a, b): return int(a * b / gcd(a, b)) def multiple_lcm(*numbers): return reduce(lcm, numbers)``` ndc85430 likes this post Skaperen Black Knight Posts: 3,059 Threads: 957 Joined: Sep 2016 Reputation: 12 Likes received: 97 #3 Aug-10-2019, 01:00 AM yes, that is true, that's how i wrote a better gcd() that handles whatever is given to it. What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American. « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post isinstance() arg2 is limited to a type or a tuple of types Skaperen 5 133 Dec-02-2019, 06:07 PM Last Post: Skaperen Distributed size limited queue implementation? johsmi96 1 261 May-08-2019, 07:29 AM Last Post: DeaD_EyE

Forum Jump:

Users browsing this thread: 1 Guest(s)