Programming-Idioms

History of Idiom 74 > diff from v26 to v27

Edit summary for version 27 :
[Clojure] Fixed a type where b was returned instead of a.

Version 26

2019-09-26, 16:38:11

Version 27

2019-09-26, 16:39:11

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
(defn gcd [a b]
  (if (zero? b)
    b
    (recur b (mod a b))))
Code
(defn gcd [a b]
  (if (zero? b)
    a
    (recur b (mod a b))))