Logo

Programming-Idioms

History of Idiom 75 > diff from v11 to v12

Edit summary for version 12 by :

Version 11

2015-09-05, 14:56:35

Version 12

2015-09-05, 14:57:29

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