TheAlgorithms-Ruby/discrete_mathematics/euclidean_gcd.rb
Vitor Oliveira e21120857d Clean up
2021-02-06 23:05:54 -08:00

14 lines
282 B
Ruby

# https://en.wikipedia.org/wiki/Euclidean_algorithm
def euclidean_gcd(a, b)
while b != 0
t = b
b = a % b
a = t
end
a
end
puts 'GCD(3, 5) = ' + euclidean_gcd(3, 5).to_s
puts 'GCD(3, 6) = ' + euclidean_gcd(3, 6).to_s
puts 'GCD(6, 3) = ' + euclidean_gcd(6, 3).to_s