Skip to content

Commit 0edb6ec

Browse files
authored
Add files via upload
1 parent ec3b118 commit 0edb6ec

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

Day12/EvenAndOdd.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def solution(num):
2+
if num % 2 == 0:
3+
return "Even"
4+
else:
5+
return "Odd"
6+
7+
print(solution(3))
8+
print(solution(4))

Day12/KeyPad.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# 내 풀이 실패
2+
def solution(numbers, hand):
3+
answer = ''
4+
5+
current_left_hand_number = '*'
6+
current_right_hand_number = '#'
7+
8+
number_map_dict = {
9+
1: [0, 0],
10+
2: [0, 1],
11+
3: [0, 2],
12+
13+
4: [1, 0],
14+
5: [1, 1],
15+
6: [1, 2],
16+
17+
7: [2, 0],
18+
8: [2, 1],
19+
9: [2, 2],
20+
21+
'*': [3, 0],
22+
0: [3, 1],
23+
'#': [3, 2],
24+
}
25+
26+
for current_number in numbers:
27+
if current_number == 1 or current_number == 4 or current_number == 7:
28+
answer += 'L'
29+
current_left_hand_number = current_number
30+
elif current_number == 3 or current_number == 6 or current_number == 9:
31+
answer += 'R'
32+
current_right_hand_number = current_number
33+
else:
34+
left_hand_distance = \
35+
abs(number_map_dict[current_number][0] - number_map_dict[current_left_hand_number][0]) \
36+
+ abs(number_map_dict[current_number][1] - number_map_dict[current_left_hand_number][1])
37+
38+
right_hand_distance = \
39+
abs(number_map_dict[current_number][0] - number_map_dict[current_right_hand_number][0]) \
40+
+ abs(number_map_dict[current_number][1] - number_map_dict[current_right_hand_number][1])
41+
42+
if left_hand_distance == right_hand_distance:
43+
if hand == 'left':
44+
answer += 'L'
45+
current_left_hand_number = current_number
46+
else:
47+
answer += 'R'
48+
current_right_hand_number = current_number
49+
elif left_hand_distance < right_hand_distance:
50+
answer += 'L'
51+
current_left_hand_number = current_number
52+
else:
53+
answer += 'R'
54+
current_right_hand_number = current_number
55+
return answer
56+
57+
58+
print(solution([1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5], "right"))
59+
print(solution([1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5], "right") == "LRLLLRLLRRL")
60+
61+
print(solution([7, 0, 8, 2, 8, 3, 1, 5, 7, 6, 2], "left"))
62+
print(solution([7, 0, 8, 2, 8, 3, 1, 5, 7, 6, 2], "left") == "LRLLRRLLLRR")
63+
64+
print(solution([1, 2, 3, 4, 5, 6, 7, 8, 9, 0], "right"))
65+
print(solution([1, 2, 3, 4, 5, 6, 7, 8, 9, 0], "right") == "LLRLLRLLRL")

Day12/MaxAndMin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def solution(n, m):
2+
def gcd(x,y):
3+
while(y):
4+
x,y = y, x%y
5+
return x
6+
def lcm(x,y):
7+
result = (x*y)//gcd(x,y)
8+
return result
9+
10+
x = gcd(n,m)
11+
y = lcm(n,m)
12+
return [x,y]
13+
14+
print(solution(3, 12))
15+
print(solution(2, 5))

Day12/RemovedMinNumber.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def solution(arr):
2+
del arr[arr.index(min(arr))]
3+
if len(arr) == 0:
4+
arr.append(-1)
5+
return arr
6+
7+
arr1 = [4,3,2,1]
8+
arr2 = [10]
9+
10+
print(solution(arr1))
11+
12+
print(solution(arr2))

Day12/SqurtTest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import math
2+
3+
def solution(n):
4+
if math.sqrt(n) % 1 == 0:
5+
return (math.sqrt(n)+1)**2
6+
return -1
7+
8+
print(solution(121))
9+
print(solution(3))

0 commit comments

Comments
 (0)