We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 6a3365c + 7e8753b commit e7ce71eCopy full SHA for e7ce71e
Recursive/gcd.py
@@ -0,0 +1,12 @@
1
+'''
2
+The GCD algorithm computes the greatest common divisor of two numbers A and B recursively.
3
4
+
5
+def gcd(x, y):
6
+ if (y==0): # base case
7
+ return x
8
+ else: # recursive case
9
+ return gcd(y, x%y)
10
11
+if __name__ == "__main__":
12
+ print (gcd(x=100, y=20))
Recursive/n_choose_k.py
+The N choose K algorithm computes the binomial coefficient C(N, K)
+def nchoosek(n, k):
+ if (k == 0) or (k == n): # base case
+ return 1
+ return nchoosek(n-1, k-1) + nchoosek(n-1, k)
+ print (nchoosek(n=5, k=3))
0 commit comments