#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



Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s