Skip to content

Instantly share code, notes, and snippets.

@opamp
Created July 6, 2011 11:14
Show Gist options
  • Save opamp/1067015 to your computer and use it in GitHub Desktop.
Save opamp/1067015 to your computer and use it in GitHub Desktop.
Euclidean algorithm
#!/usr/bin/env ruby
#-*- encoding:utf-8 -*-
# コマンドライン引数は 第一引数 >= 第二引数 でなければならない。
if ARGV.size != 2 then
STDERR::puts "Arguments error."
exit 1
end
unless ARGV[0].to_i >= ARGV[1].to_i then
STDERR::puts "arg1 >= arg2"
exit 1
end
def eal(m,n)
return m if n == 0
return eal(n,m%n)
end
r = eal(ARGV[0].to_i,ARGV[1].to_i)
puts "= #{r}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment