Sha256: 66be0c8daf1cf09b8fb2771a711d2a3a6f63de1f2be72f79f1347fc5882cd71e

Contents?: true

Size: 308 Bytes

Versions: 25

Compression:

Stored size: 308 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

a, b = ARGV[0..1].map {|arg| arg.to_i}
puts "The GCD of %d and %d is %d" % [a, b, gcd(a, b)]

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
rbx-trepanning-0.0.1-universal-rubinius test/example/gcd.rb
trepanning-0.0.9 test/example/gcd.rb
trepanning-0.0.8 test/example/gcd.rb
trepanning-0.0.6 test/example/gcd.rb
trepanning-0.0.4 test/example/gcd.rb