mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-15 06:12:59 +00:00
907c3cad09
Recursively.
16 lines
320 B
Plaintext
16 lines
320 B
Plaintext
# For what Recursion is, please check theory/recursion
|
|
|
|
# Simple Factorial Python Recursion
|
|
def factorial(n) :
|
|
if n == 0 :
|
|
return 1
|
|
else :
|
|
return n * factorial(n-1)
|
|
|
|
# Simple Greatest Common Divisor Recursion
|
|
def gcd(x, y) :
|
|
if y == 0 :
|
|
return x
|
|
else :
|
|
return gcd(y, x%y)
|