Sha256: cf1a779819b7216a34cd1d5b499de487991a511b77bc6ecb560e1dc0628bde8e

Contents?: true

Size: 414 Bytes

Versions: 5

Compression:

Stored size: 414 Bytes

Contents

#!/usr/bin/env ruby
require 'thread_frame'
tf = RubyVM::Frame.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

5 entries across 5 versions & 1 rubygems

Version Path
trepanning-2.15.35 test/example/gcd1.rb
trepanning-1.93.35 test/example/gcd1.rb
trepanning-2.15.33 test/example/gcd1.rb
trepanning-1.93.32 test/example/gcd1.rb
trepanning-0.1.6 test/example/gcd1.rb