LoginSignup
0
1

More than 3 years have passed since last update.

再帰表現メモ

Last updated at Posted at 2020-03-05

ユークリッド互除法

修正:2020.3.5

普通の書き方

main.py
def euclid_algolithm_1(a, b):
    while True:
        r = a % b
        if r == 0:
            return b
        a, b = b, r

再帰表現で書く

main.py
def euclid_algolithm_2(a, b):
    r = a % b
    if r == 0:
        return b
    return euclid_algorithm_2(b, r)
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1