programming-examples/ruby/Algorithms/gcd.rb

10 lines
202 B
Ruby
Raw Normal View History

2019-11-15 12:59:38 +01:00
# Computes the greatest common divisor of two nonnegative integers p and q,
# see test/gcd_test.rb
module CommonDivisor
def self.gcd(p, q)
return p if q == 0
r = p % q
gcd(q, r)
end
end