ProgrammingElixir1.6-MyTurns/ModulesAndFunctions-5.exs

16 lines
342 B
Elixir
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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; its gcd(y, rem(x,y)) otherwise.
defmodule MyModule do
def gcd(x,0) do
x
end
def gcd(x,y) do
gcd(y, rem(x, y))
end
end
IO.puts MyModule.gcd(17*5, 13*5)