SimplePrograms challenge
Steve Howell
showell30 at yahoo.com
Thu Jun 14 22:07:18 EDT 2007
--- Joe Riopel <goon12 at gmail.com> wrote:
> 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.
>
I'm a little wary of having the page contain too many
mathematical examples, although I admit that I've
already included Fibonacci and Eratosthenes. (And
your example shares in common with those two that it's
a classic example.)
Feel free to post your example on the page, but please
use slightly more descriptive identifiers (e.g. change
hcd to highest_common_denominator or
largest_common_denominator), and also have the program
print out the results.
Thanks.
-- Steve
____________________________________________________________________________________
Yahoo! oneSearch: Finally, mobile search
that gives answers, not web links.
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC
More information about the Python-list
mailing list