Sha256: 9e05e39b452ad63067455d5c97896b88d693e72a789ea0e5e6bd195a1541fa90

Contents?: true

Size: 217 Bytes

Versions: 14

Compression:

Stored size: 217 Bytes

Contents

#!/usr/bin/env ruby

# GCD. We assume positive numbers
def gcd(a, b)
  # Make: a <= b
  if a > b
    a, b = [b, a]
  end

  return nil if a <= 0

  if a == 1 or b-a == 0
    return a
  end
  gcd(b-a, a)
end

gcd(3,5)

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
debugger-1.2.4 test/gcd.rb
debugger-1.2.3 test/gcd.rb
debugger-1.2.2 test/gcd.rb
debugger-1.2.1 test/gcd.rb
debugger-1.2.0 test/gcd.rb
debugger-1.1.4 test/gcd.rb
debugger-1.1.3 test/gcd.rb
debugger-1.1.2 test/gcd.rb
debugger-1.1.1 test/gcd.rb
debugger-1.1.0 test/gcd.rb
debugger-1.0.1 test/gcd.rb
debugger-1.0.0 test/gcd.rb
debugger-1.0.0.rc2 test/gcd.rb
debugger-1.0.0.rc1 test/gcd.rb