Skip to content

Commit d3fcf2e

Browse files
Add files via upload
1 parent 1ead54c commit d3fcf2e

File tree

3 files changed

+122
-16
lines changed

3 files changed

+122
-16
lines changed

Day15/Budget.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1+
# 37. 예산
2+
13
def solution(d, budget):
24
answer = 0
5+
6+
# 총 가능 금액
7+
total = 0
8+
39
d.sort()
4-
5-
for dVal in d:
6-
budget -= dVal
7-
answer += 1
8-
if budget < 0:
10+
for i in d:
11+
if total + i <= budget:
12+
total += i
13+
answer += 1
14+
else:
915
break
10-
11-
if budget >= 0:
12-
return answer
13-
else:
14-
return answer -1
16+
return answer
17+
18+
d_1 = [1, 3, 2, 5, 4]
19+
d_2 = [2, 2, 3, 3]
1520

16-
d1 = [1,3,2,5,4]
17-
d2 = [2,2,3,3]
21+
budget_1 = 9
22+
budget_2 = 10
1823

19-
budget1 = 9
20-
budget2 = 10
24+
print(solution(d_1, budget_1))
25+
print(solution(d_2, budget_2))
26+
27+
def solution_best(d, budget):
28+
answer = 0
29+
30+
d.sort()
31+
while budget < sum(d):
32+
d.pop()
33+
answer = len(d)
34+
return answer
2135

22-
print(solution(d1, budget1))
23-
print(solution(d2, budget2))
36+
print(solution_best(d_1, budget_1))
37+
print(solution_best(d_2, budget_2))

Day15/InnerProduct.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 39. 내적
2+
3+
def solution(a, b):
4+
answer = 1234567890
5+
6+
Inner_Product = 0
7+
for i, j in zip(a, b):
8+
Inner_Product += i * j
9+
10+
answer = Inner_Product
11+
return answer
12+
13+
a_1 = [1, 2, 3, 4]
14+
a_2 = [-1, 0, 1]
15+
16+
b_1 = [-3, -1, 0, 2]
17+
b_2 = [1, 0, -1]
18+
19+
print(solution(a_1, b_1))
20+
print(solution(a_2, b_2))

Day15/SecretMap.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# 28. 비밀 지도
2+
3+
def solution(n, arr1, arr2):
4+
answer = []
5+
6+
# 지도 1 2진수 문자열로 바꾼 리스트 ... 9 -> '0b1001'
7+
bi_map1_lst = [bin(i) for i in arr1]
8+
9+
# 지도 1 2진수 문자열 정리한 리스트 ... '0b1001' -> '1001'
10+
map1_lst = []
11+
12+
# 지도 2 2진수 문자열로 바꾼 리스트(지도 1과 같음)
13+
bi_map2_lst = [bin(i) for i in arr2]
14+
15+
# 지도 2 2진수 문자열 정리한 리스트(지도 1과 같음)
16+
map2_lst = []
17+
18+
# '0b1001' -> '1001'
19+
for one in bi_map1_lst:
20+
one = one[2:]
21+
map1_lst.append(one)
22+
23+
for one in bi_map2_lst:
24+
one = one[2:]
25+
map2_lst.append(one)
26+
27+
# '1001' -> '01001' or '01001' -> '1001'
28+
for i in range(len(map1_lst)):
29+
if len(map1_lst[i]) < n:
30+
map1_lst[i] = (n - len(map1_lst[i])) * '0' + map1_lst[i]
31+
32+
for i in range(len(map2_lst)):
33+
if len(map2_lst[i]) < n:
34+
map2_lst[i] = (n - len(map2_lst[i])) * '0' + map2_lst[i]
35+
36+
for line1, line2 in zip(map1_lst, map2_lst):
37+
# 줄 별 문자열 저장 ... '#####'
38+
line_str = ''
39+
for sq1, sq2 in zip(line1, line2):
40+
if sq1 == '1' or sq2 == '1':
41+
line_str += '#'
42+
elif sq1 == '0' and sq2 == '0':
43+
line_str += ' '
44+
answer.append(line_str)
45+
return answer
46+
47+
n_1 = 5
48+
arr1_1 = [9, 20, 28, 18, 11]
49+
arr2_1 = [30, 1, 21, 17, 28]
50+
51+
n_2 = 6
52+
arr1_2 = [46, 33, 33, 22, 31, 50]
53+
arr2_2 = [27, 56, 19, 14, 14, 10]
54+
55+
print(solution(n_1, arr1_1, arr2_1))
56+
print(solution(n_2, arr1_2, arr2_2))
57+
print()
58+
59+
def solution_best(n, arr1, arr2):
60+
answer = []
61+
62+
for i, j in zip(arr1, arr2):
63+
a12 = bin(i | j)[2:]
64+
a12 = a12.rjust(n, '0')
65+
a12 = a12.replace('1', '#')
66+
a12 = a12.replace('0', ' ')
67+
answer.append(a12)
68+
69+
return answer
70+
71+
print(solution_best(n_1, arr1_1, arr2_1))
72+
print(solution_best(n_2, arr1_2, arr2_2))

0 commit comments

Comments
 (0)