Permalink
Browse files

gcd euclidean

  • Loading branch information...
sole committed Oct 21, 2010
1 parent db87d38 commit 2b65be858a6929739c8c78b1130e417499ba7611
Showing with 22 additions and 0 deletions.
  1. +2 −0 README
  2. +20 −0 algorithms/gcd_euclidean.java
View
2 README
@@ -13,6 +13,8 @@ Old style 'table' of contents:
|
+-- custom_sort.py - sort by any object property using lambda functions
|
++-- gcd_euclidean.java - find greatest common divisor by the Euclidean algorithm
+|
+ audio
|
+-- generate_noise_test_python - create a wav file with 300 seconds of noise in python
@@ -0,0 +1,20 @@
+// find greatest common divisor by the Euclidean algorithm
+// from http://en.wikipedia.org/wiki/Greatest_common_divisor#Using_Euclid.27s_algorithm
+int gcd(int a, int b)
+{
+ if(a == 0)
+ {
+ return b;
+ }
+ else if(b == 0)
+ {
+ return a;
+ }
+ else
+ {
+ int maxValue = Math.max(a, b);
+ int minValue = Math.min(a, b);
+
+ return gcd(minValue, maxValue % minValue);
+ }
+}

0 comments on commit 2b65be8

Please sign in to comment.