Created
July 6, 2011 11:14
-
-
Save opamp/1067015 to your computer and use it in GitHub Desktop.
Euclidean algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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