Sha256: a03f19084621737b8b5990234a96f5d140472bf8817db33876ce1f4dce1e7ef0

Contents?: true

Size: 420 Bytes

Versions: 12

Compression:

Stored size: 420 Bytes

Contents

#!/usr/bin/env ruby
require 'thread_frame'
tf = RubyVM::ThreadFrame.current
iseq = tf.iseq
p iseq.child_iseqs
puts iseq.disassemble

# 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

12 entries across 12 versions & 2 rubygems

Version Path
trepanning-0.1.4 test/example/gcd1.rb
trepanning-0.1.3 test/example/gcd1.rb
trepanning-0.1.2 test/example/gcd1.rb
trepanning-0.1.1 test/example/gcd1.rb
trepanning-0.1.0 test/example/gcd1.rb
rbx-trepanning-0.0.3-universal-rubinius-1.2 test/example/gcd1.rb
rbx-trepanning-0.0.2-universal-rubinius-1.2 test/example/gcd1.rb
rbx-trepanning-0.0.1-universal-rubinius test/example/gcd1.rb
trepanning-0.0.9 test/example/gcd1.rb
trepanning-0.0.8 test/example/gcd1.rb
trepanning-0.0.6 test/example/gcd1.rb
trepanning-0.0.4 test/example/gcd1.rb