12.07.2015 Views

Think Python - Denison University

Think Python - Denison University

Think Python - Denison University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

62 Chapter 6. Fruitful functionsOne way to find the GCD of two numbers is Euclid’s algorithm, which is based on the observationthat if r is the remainder when a is divided by b, then gcd(a,b)=gcd(b,r). As a base case, we canconsider gcd(a,0)=a.Writeafunctioncalledgcdthattakesparametersaandbandreturnstheirgreatestcommondivisor.Ifyou need help, seewikipedia.org/wiki/Euclidean_algorithm.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!