Skip to content

Commit 88e5341

Browse files
Add files via upload
1 parent b9b1129 commit 88e5341

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed

Day13/CraneDrawDollMachine.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# 9. 크레인 인형뽑기 게임
2+
import numpy as np
3+
4+
def solution(board, moves):
5+
answer = 0
6+
7+
# 바구니 리스트
8+
bucket = []
9+
10+
for move in moves:
11+
for i in range(len(board)):
12+
if board[i][move - 1] > 0:
13+
bucket.append(board[i][move - 1])
14+
board[i][move - 1] = 0
15+
16+
if bucket[-1:] == bucket[-2:-1]:
17+
answer += 2
18+
bucket = bucket[:-2]
19+
break
20+
21+
return answer
22+
23+
24+
board_1 = [[0, 0, 0, 0, 0],
25+
[0, 0, 1, 0, 3],
26+
[0, 2, 5, 0, 1],
27+
[4, 2, 4, 4, 2],
28+
[3, 5, 1, 3, 1]]
29+
30+
moves_1 = [1, 5, 3, 5, 1, 2, 1, 4]
31+
print(solution(board_1, moves_1))
32+
33+
# 내 풀이 -> 틀림
34+
def solution_error(board, moves):
35+
answer = 0
36+
37+
# 바구니 리스트
38+
basket = []
39+
up_down_basket = []
40+
41+
# Numpy의 array
42+
board_lst_to_arr = np.array(board).copy()
43+
44+
for i in moves:
45+
machine_pick_row = board_lst_to_arr[:, i - 1]
46+
for j in machine_pick_row:
47+
if j != 0:
48+
basket.append(j)
49+
machine_pick_row[np.where(machine_pick_row == j)] = 0
50+
51+
else:
52+
continue
53+
54+
break
55+
56+
# print(basket)
57+
58+
59+
# 첫 비교 값
60+
first = 0
61+
62+
for i in basket:
63+
first = basket.pop(0)
64+
if i != first:
65+
up_down_basket.append(first)
66+
first = basket.pop(0)
67+
elif i == first:
68+
answer += 2
69+
basket.pop(0)
70+
elif up_down_basket[-1] == first:
71+
answer += 2
72+
up_down_basket.pop(-1)
73+
74+
return answer
75+
76+
# print(solution_error(board_1, moves_1))
77+
78+
def solution_best(board, moves):
79+
answer = 0
80+
81+
return answer
82+
83+
# print(solution_best(board_1, moves_1))
84+
85+
def solution_other(board, moves):
86+
answer = []
87+
88+
# 바구니 리스트
89+
bucket = []
90+
91+
for move in moves:
92+
for i in range(len(board)):
93+
if board[i][move - 1] > 0:
94+
bucket.append(board[i][move - 1])
95+
board[i][move - 1] = 0
96+
97+
if bucket[-1:] == bucket[-2:-1]:
98+
answer += bucket[-1:]
99+
bucket = bucket[:-2]
100+
break
101+
102+
return len(answer) * 2
103+
104+
# print(solution_other(board_1, moves_1))
105+
106+

Day13/GuessColats.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# 25. 콜라츠 추측
2+
3+
def solution(num):
4+
answer = 0
5+
6+
while num != 1:
7+
if answer < 500:
8+
if num % 2 == 0:
9+
num /= 2
10+
else:
11+
num = num * 3 + 1
12+
answer += 1
13+
else:
14+
answer = -1
15+
return answer
16+
return answer
17+
18+
num_1 = 6
19+
num_2 = 16
20+
num_3 = 626331
21+
22+
print(solution(num_1))
23+
print(solution(num_2))
24+
print(solution(num_3))
25+
26+
def solution_best(num):
27+
answer = -1
28+
29+
for i in range(500):
30+
num = num / 2 if num % 2 == 0 else num * 3 + 1
31+
32+
if num == 1:
33+
answer = num + 1
34+
return answer
35+
return answer
36+
37+
print(solution_best(num_1))
38+
print(solution_best(num_2))
39+
print(solution_best(num_3))

Day13/HazardNumber.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 26. 햐샤드 수
2+
3+
def solution(x):
4+
answer = True
5+
6+
x_lst = [int(i) for i in str(x)]
7+
8+
if x % sum(x_lst) == 0:
9+
answer = True
10+
else:
11+
answer = False
12+
return answer
13+
14+
x_1 = 10
15+
x_2 = 12
16+
x_3 = 11
17+
x_4 = 13
18+
19+
print(solution(x_1))
20+
print(solution(x_2))
21+
print(solution(x_3))
22+
print(solution(x_4))
23+
24+
def solution_best(x):
25+
answer = x % sum([int(c) for c in str(x)]) == 0
26+
27+
return answer
28+
29+
# print(solution_best(x_1))
30+
# print(solution_best(x_2))
31+
# print(solution_best(x_3))
32+
# print(solution_best(x_4))

0 commit comments

Comments
 (0)