mirror of
https://github.com/wnagrodzki/ProgrammingElixir1.6-MyTurns.git
synced 2025-05-03 17:41:41 +02:00
16 lines
342 B
Elixir
16 lines
342 B
Elixir
# 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 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)
|