Skip to content

Instantly share code, notes, and snippets.

@wongyouth
Created March 29, 2018 15:44
Show Gist options
  • Select an option

  • Save wongyouth/2da9c1e319015c63bbb4e0a1c47c1028 to your computer and use it in GitHub Desktop.

Select an option

Save wongyouth/2da9c1e319015c63bbb4e0a1c47c1028 to your computer and use it in GitHub Desktop.
求最大公约数
# Write a function gcd(x,y) that finds the greatest common divisor between two nonnegative integers.
# Algebraically, gcd(x,y) is x if y is zero; it’s gcd(y, rem(x,y)) otherwise.
defmodule Mathx do
def gcd(x, 0) do
x
end
def gcd(x, y) do
gcd(y, rem(x,y)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment