Last active
December 31, 2015 05:59
-
-
Save st98/7944245 to your computer and use it in GitHub Desktop.
Rubyの練習。ユークリッドの互除法を使って2つの整数の最大公約数を求めます。
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
# ユークリッドの互除法(非再帰) | |
def gcd_euclid_l(a, b) | |
while 0 do | |
break if b == 0 | |
a, b = b, a % b | |
end | |
a | |
end | |
# ユークリッドの互除法(再帰) | |
def gcd_euclid_r(a, b) | |
if b == 0 then | |
a | |
else | |
gcd(b, a % b) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment