Created
March 29, 2018 15:44
-
-
Save wongyouth/2da9c1e319015c63bbb4e0a1c47c1028 to your computer and use it in GitHub Desktop.
求最大公约数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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