Sha256: 408144bd139d4ff4b1d3b29f340e72aec7826fc0151ac1dbac5108a5678806f0

Contents?: true

Size: 224 Bytes

Versions: 86

Compression:

Stored size: 224 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
  return gcd(b-a, a)
end

gcd(3,5)

Version data entries

86 entries across 75 versions & 8 rubygems

Version Path
ruby-debug-0.10.4 test/gcd.rb
rackjour-0.1.8 vendor/gems/gems/ruby-debug-0.10.3/test/gcd.rb
ruby-debug-0.10.3 test/gcd.rb
ruby-debug-0.10.2 test/gcd.rb
ruby-debug-0.10.1 test/gcd.rb
ruby-debug-0.10.0 test/gcd.rb