Logo

Programming-Idioms

History of Idiom 75 > diff from v18 to v19

Edit summary for version 19 by programming-idioms.org:
[Elixir] +DemoURL

Version 18

2017-02-07, 22:52:32

Version 19

2017-02-07, 22:54:44

Idiom #75 Compute LCM

Compute the least common multiple x of big integers a and b. Use an integer type able to handle huge numbers.

Idiom #75 Compute LCM

Compute the least common multiple x of big integers a and b. Use an integer type able to handle huge numbers.

Code
defmodule BasicMath do
	def gcd(a, 0), do: a
	def gcd(0, b), do: b
	def gcd(a, b), do: gcd(b, rem(a,b))
	
	def lcm(0, 0), do: 0
	def lcm(a, b), do: (a*b)/gcd(a,b)
end
Code
defmodule BasicMath do
	def gcd(a, 0), do: a
	def gcd(0, b), do: b
	def gcd(a, b), do: gcd(b, rem(a,b))
	
	def lcm(0, 0), do: 0
	def lcm(a, b), do: (a*b)/gcd(a,b)
end
Demo URL
http://play.elixirbyexample.com/s/f3f9976e44