Programming-Idioms

History of Idiom 74 > diff from v20 to v21

Edit summary for version 21 :
[Elixir] +DemoURL

Version 20

2016-12-04, 21:28:52

Version 21

2017-02-07, 22:11:30

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
defmodule Gcd do
  def gcd(x, 0), do: x
  def gcd(x, y), do: gcd(y, rem(x,y))
end

x = Gcd.gcd(a, b)
Code
defmodule Gcd do
  def gcd(x, 0), do: x
  def gcd(x, y), do: gcd(y, rem(x,y))
end

x = Gcd.gcd(a, b)
Demo URL
http://play.elixirbyexample.com/s/7454d40fc2