mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-27 21:58:57 +01:00
17 lines
309 B
Ruby
17 lines
309 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
|
||
|
return 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
|
||
|
|
||
|
|