#WSQ06 Greatest Common Divisor

I was not sure if I should write the GCD method by myself or if I could use an already implemented method.

Of course I read about The Euclidean GCD algorithm because I am too lazy to search it in the Tec library. And this is also interesting, the pseudo-code algorithm and a formal proof of correctness from proofwiki.

This recursive algorithm is basically a method for finding the greatest common divisor of two integers. So you take two integers a and b such that |a| > |b|, then you calculate the remainder, call it r, of a/b. Next, set a = b and b = r

And i was writing the GCD class, but then I told myself:

Why should I write this if someone else has already did?

And of course also because this class is about Object Oriented Programming and not about Algorithms, and also, that’s one of the big advantages of OOP, you can use someone else’s code without worrying if your code will be compatible with other persons’ code, because it should

And after all these philosophical thoughts I decided to keep it simple and just use the BigInteger java class I found here get gcd java and here Big Integer Class.

Screenshot from 2016-02-04 11:54:28

I also pushed it to GitHub here: WSQ06-GCD.

Screenshot from 2016-02-08 12:40:06

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s