Logo

Programming-Idioms

History of Idiom 75 > diff from v29 to v30

Edit summary for version 30 by programming-idioms.org:
[Elixir] Dead link: play.elixirbyexample.com has been down for a while

Version 29

2019-10-04, 23:18:16

Version 30

2019-10-14, 12:27:13

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