Skip to content
This repository was archived by the owner on Aug 26, 2020. It is now read-only.

Commit 639db48

Browse files
authored
added assignments
0 parents commit 639db48

File tree

8 files changed

+117
-0
lines changed

8 files changed

+117
-0
lines changed

APlusB.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# python3
2+
3+
4+
def sum_of_two_digits(first_digit, second_digit):
5+
return first_digit + second_digit
6+
7+
if __name__ == '__main__':
8+
a, b = map(int, input().split())
9+
print(sum_of_two_digits(a, b))

fibonacci.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Uses python3
2+
fibs={
3+
0:0,
4+
1:1
5+
}
6+
def calc_fib(n):
7+
if n in fibs:
8+
return fibs.get(n)
9+
else:
10+
fibs.update({n:calc_fib(n-1) + calc_fib(n-2)})
11+
return fibs.get(n)
12+
13+
n = int(input())
14+
print(calc_fib(n))

fibonacci_huge.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Uses python3
2+
3+
def pisanoPeriod(m):
4+
previous, current = 0, 1
5+
for i in range(0, m * m):
6+
previous, current = current, (previous + current) % m
7+
if (previous == 0 and current == 1):
8+
return i + 1
9+
10+
def get_fibonacci_huge_naive(n, m):
11+
pisano_period = pisanoPeriod(m)
12+
n = n % pisano_period
13+
previous, current = 0, 1
14+
if n==0:
15+
return 0
16+
elif n==1:
17+
return 1
18+
for i in range(n-1):
19+
previous, current = current, previous + current
20+
return (current % m)
21+
22+
if __name__ == '__main__':
23+
n, m = map(int, input().split())
24+
print(get_fibonacci_huge_naive(n, m))

fibonacci_last_digit.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Uses python3
2+
fibs={
3+
0:0,
4+
1:1
5+
}
6+
def get_fibonacci_last_digit_naive(n):
7+
if n in fibs:
8+
return fibs.get(n)
9+
for i in range(2,n+1):
10+
fibs.update({i: (fibs.get(i-1)+fibs.get(i-2))%10})
11+
return fibs.get(n)
12+
13+
if __name__ == '__main__':
14+
n = int(input())
15+
print(get_fibonacci_last_digit_naive(n))
16+

fibonacci_sum_last_digit.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Uses python3
2+
# Uses python3
3+
fibs={
4+
0:0,
5+
1:1
6+
}
7+
8+
def fibonacci_sum_naive(n):
9+
if n in fibs:
10+
return fibs.get(n)
11+
n=(n+2)%60
12+
for i in range(2,n+1):
13+
fibs.update({i: (fibs.get(i-1)%10+fibs.get(i-2)%10)%10})
14+
if(fibs.get(n) == 0):
15+
return 9
16+
return (fibs.get(n) % 10) - 1
17+
18+
if __name__ == '__main__':
19+
n = int(input())
20+
print(fibonacci_sum_naive(n))

gcd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Uses python3
2+
def gcd_naive(a, b):
3+
if(b==0):
4+
return a
5+
return gcd_naive(b,a%b)
6+
7+
if __name__ == "__main__":
8+
a, b = map(int, input().split())
9+
print(gcd_naive(a, b))

lcm.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Uses python3
2+
def gcd_naive(a, b):
3+
if(b==0):
4+
return a
5+
return gcd_naive(b,a%b)
6+
7+
def lcm_naive(a, b):
8+
return int((max(a,b)/gcd_naive(a,b))*min(a,b))
9+
10+
if __name__ == '__main__':
11+
a, b = map(int, input().split())
12+
print(lcm_naive(a, b))
13+

max_pairwise_product.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# python3
2+
3+
4+
def max_pairwise_product(numbers):
5+
numbers.sort(reverse=True)
6+
return (numbers[0]*numbers[1])
7+
8+
9+
if __name__ == '__main__':
10+
input_n = int(input())
11+
input_numbers = [int(x) for x in input().split()]
12+
print(max_pairwise_product(input_numbers))

0 commit comments

Comments
 (0)