[Tutor] A better way for greatest common divisor

David Hutto smokefloat at gmail.com
Fri Jul 30 04:48:15 CEST 2010


On Thu, Jul 29, 2010 at 10:36 PM, James Mills
<prologic at shortcircuit.net.au> wrote:
> On Fri, Jul 30, 2010 at 12:22 PM, Richard D. Moores <rdmoores at gmail.com> wrote:
>> On Thu, Jul 29, 2010 at 19:10, James Mills <prologic at shortcircuit.net.au> wrote:
>>> On Fri, Jul 30, 2010 at 11:47 AM, David Hutto <smokefloat at gmail.com> wrote:
>>>> This is basically to get feedback, on a better way to show the
>>>> greatest common divisor in fraction, in order to reduce it fully, than
>>>> the one I've come up with. I'm sure there are better ways, so if you
>>>> have simpler method, or critique of what I've done, let me know.
>>>
>>> [snip]
>>>
>>> I have a far simpler solution:
>>>
>>>>>> from tools import gcd
>>>>>> gcd(20, 5)
>>> 5
>>
>> In Python 3.1 that would be
>>>>> from fractions import gcd
>>>>> gcd(20,5)
>> 5
>
> Yes. The code I provided above was code I wrote
> for various Euler problems I had been working on
> a whiel back. It was written for 2.x
>
> cheers
> James
>
> --
> -- James Mills
> --
> -- "Problems are solved by method"
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Actually, I knew there was a function in one of the modules, this was
for an exercise in Building Skills in python. So it was more from
scratch than use a prebuilt function.


More information about the Tutor mailing list