SimplePrograms challenge

Joe Riopel goon12 at gmail.com
Thu Jun 14 22:00:05 EDT 2007


How about this one for recursion and control flow:

>>> def hcd(m,n):
...     r = m % n
...     if( r > 0 ):
...             hcd(n, r)
...     else:
...             print "hcd = %d" % (n,)
...
>>> hcd(119, 544)
hcd = 17
>>>

It calculates the highest common denominator for m and n. Plus it's E1
in TAoCP by Knuth.



More information about the Python-list mailing list