Skip to content

Commit 76221a6

Browse files
Add files via upload
1 parent 5a1b011 commit 76221a6

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

W1_L1_gcd1.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def gcd(m, n):
2+
m_lst = []
3+
for i in range(1, m+1):
4+
if m % i == 0:
5+
m_lst.append(i)
6+
7+
n_lst = []
8+
for i in range(1, n+1):
9+
if n % i == 0:
10+
n_lst.append(i)
11+
12+
common_lst = []
13+
for i in m_lst:
14+
if i in n_lst:
15+
common_lst.append(i)
16+
17+
return common_lst[-1]
18+
19+
print(gcd(15, 20))

W1_L2_gcd2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def gcd(m, n):
2+
for i in range(min(m, n), 0, -1):
3+
if m % i == 0 and n % i == 0:
4+
return i
5+
6+
7+
8+
print(gcd(150, 75))

W1_L2_gcd_euclid.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def gcd(m, n):
2+
if m < n:
3+
m, n = n, m
4+
5+
if m % n == 0:
6+
return n
7+
else:
8+
diff = m - n
9+
return gcd(max(n, diff), min(n, diff))
10+
11+
print(gcd(75, 30))

W1_L3_gcd_best.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def gcd(m, n):
2+
3+
if n == 0:
4+
return m
5+
return gcd(n, m % n)
6+
7+
# if m < n:
8+
# m, n = n, m
9+
10+
# if m % n == 0:
11+
# return n
12+
# else:
13+
# return gcd(n, m % n) # m % n < n always
14+
15+
print(gcd(30, 75))

W1_quiz.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# def h(x):
2+
# (d,n) = (1,0)
3+
# while d <= x:
4+
# (d,n) = (d*3,n+1)
5+
# return(n)
6+
7+
# print(h(27993))
8+
9+
10+
# def g(n):
11+
# s=0
12+
# for i in range(2,n):
13+
# if n%i == 0:
14+
# s = s+1
15+
# return(s)
16+
17+
# print(g(60) - g(48))
18+
19+
20+
# def f(n):
21+
# s=0
22+
# for i in range(1,n+1):
23+
# if n//i == i and n%i == 0:
24+
# s = 1
25+
# return(s%2 == 1)
26+
27+
# for i in range(1, 50):
28+
# print(i, f(i))
29+
30+
31+
32+
# def foo(m):
33+
# if m == 0:
34+
# return(0)
35+
# else:
36+
# return(m+foo(m-1))
37+
38+
# for i in range(0, 6):
39+
# print(i, foo(i), int(i*(i+1)/2))

0 commit comments

Comments
 (0)