Logo

Programming-Idioms

History of Idiom 74 > diff from v6 to v7

Edit summary for version 7 by :

Version 6

2015-08-22, 22:59:47

Version 7

2015-08-23, 19:46:39

Idiom #74 Compute GCD

Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.

Idiom #74 Compute GCD

Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.

Code
int gcd(int a, int b) {
  while (b != 0) {
    var t = b;
    b = a % t;
    a = t;
  }
  return a;
}
Demo URL
https://dartpad.dartlang.org/65e869a18a73838d10af