Programming-Idioms

History of Idiom 74 > diff from v34 to v35

Edit summary for version 35 :
[Elixir] Dead link: play.elixirbyexample.com has been down for a while

Version 34

2019-10-04, 22:40:24

Version 35

2019-10-14, 12:26:56

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