from itertools import combinations
def find_all_sums(arr):
# Use combinations to generate all possible subsets of the array
all_sums = set()
for i in range(1, len(arr) + 1):
for subset in combinations(arr, i):
all_sums.add(sum(subset))
return all_sums
def target_sum(arr, target):
all_possible_sums = find_all_sums(arr)
all_possible_sums_list = list(all_possible_sums)
length = len(all_possible_sums_list)
for i in range(length):
if all_possible_sums_list[i] == target:
return True
return False
arr = [15, 11, 12]
panda = 27
print(target_sum(arr, panda))
def missing_finder(array):
n = len(array) + 1
found = False
for j in range(1, n + 1):
found = False
for i in range(len(array)):
if array[i] == j:
found = True
break
if not found:
return j
return None
arr = [1, 2, 3, 4, 5, 6, 8]
arr2 = [4, 2, 3, 5, 6]
print(missing_finder(arr)) # Output should be 7
print(missing_finder(arr2)) # Output should be 1
'호그와트' 카테고리의 다른 글
그래 나 노래 못해 ~~ (0) | 2024.05.18 |
---|---|
crazy monster made by tryhackme GOD :: hero (0) | 2024.05.14 |
this is beauty (0) | 2024.05.13 |
Docker 설치 진짜 개 쉽게 하는 법 (Windows WSL 2) (1) | 2024.05.13 |
넘어간다제~ (0) | 2024.05.06 |