Compare commits

...
10 Commits
6 changed files with 70 additions and 2 deletions
+13 -2
View File
@@ -1,3 +1,14 @@
def is_armstrong(n:int) -> bool:
pass
digits_str = str(n)
digits_len = len(digits_str)
total = 0
for digit in digits_str:
number = int(digit)
result = number ** digits_len
total = total + result
return total == n
if __name__ == "__main__":
print(f"is_armstrong(153) = {is_armstrong(153)}")
print(f"is_armstrong(10) = {is_armstrong(10)}")
print(f"is_armstrong(9474) = {is_armstrong(9474)}")
print(f"is_armstrong(123) = {is_armstrong(123)}")
+2
View File
@@ -0,0 +1,2 @@
def intersection_of_sorted(a: list, b: list) -> list:
pass
+9
View File
@@ -0,0 +1,9 @@
def remove_duplicate_chars(s: str) -> str:
result = ""
for char in s:
if char not in result:
result += char
return result
if __name__ == "__main__":
print(f"remove_duplicate_chars('abacabad') → {remove_duplicate_chars('abacabad')}")
+13
View File
@@ -0,0 +1,13 @@
def llongest_increasing_subsequence(arr: list) -> list:
if not arr:
return []
dp = [[x] for x in arr]
for i in range(len(arr)):
for j in range(i):
if arr[j] < arr[i] and len(dp[j]) + 1 > len(dp[i]):
dp[i] = dp[j] + [arr[i]]
return max(dp, key = len)
print(dp)
if __name__ == "__main__":
print(f"llongest_increasing_subsequence([10, 9, 2, 5, 3, 7, 101, 18] -> {llongest_increasing_subsequence([10, 9, 2, 5, 3, 7, 101, 18])}")
+17
View File
@@ -0,0 +1,17 @@
def most_frequent_value(d: dict) -> tuple:
frequency = {}
for value in d.values():
if value in frequency:
frequency[value] += 1
else:
frequency[value] = 1
max_value = None
max_count = 0
for value, count in frequency.items():
if count > max_count:
max_count = count
max_value = value
return(max_value, max_count)
if __name__ == "__main__":
print(most_frequent_value({"a": 1, "b": 2, "c": 1, "d": 3}))
+16
View File
@@ -0,0 +1,16 @@
def gcd(a: int, b: int) -> int:
result = []
for i in range(1, min(a, b) + 1):
if a % i == 0 and b % i == 0:
result.append(i)
else:
continue
return max(result)
if __name__ == "__main__":
print(gcd(18, 24))