Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3차/류동준 #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions 3차/류동준_[카카오-인턴]키패드-누르기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def caldist(l_hand,r_hand, num,position,hand):
dist_l = abs(position[num][0] - position[l_hand][0]) + abs(position[num][1] - position[l_hand][1])
dist_r = abs(position[num][0] - position[r_hand][0]) + abs(position[num][1] - position[r_hand][1])
if dist_l == dist_r:
return 'R' if hand =='right' else 'L'
return 'R' if dist_l > dist_r else 'L'

def solution(numbers, hand):
position = {
1: (0,0), 2: (0,1) ,3 :(0,2),
4: (1,0), 5: (1,1) ,6 :(1,2),
7: (2,0), 8: (2,1) ,9 : (2,2),
'*':(3,0), 0:(3,1),'#': (3,2)
}

left_numbers,right_numbers = set([1,4,7,'*']),set([3,6,9,'#'])
answer = ''
l_hand = '*'
r_hand = '#'

for num in numbers:
if num in left_numbers:
answer += 'L'
l_hand = num
elif num in right_numbers:
answer += 'R'
r_hand = num
else:
result = caldist(l_hand,r_hand,num,position,hand)
if result == 'R':
r_hand = num
else:
l_hand = num
answer += result

return answer
17 changes: 17 additions & 0 deletions 3차/류동준_예산.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def solution(d, budget):
answer = 0
# d가 가장 작은 값을 순서대로 가지게 끔 함
# 혹은 d의 value를 pop 할때 d.pop(d.index(min(d))) 도 가능하기는함.
d.sort()
while (budget):
# 모든 d 를 pop 하고 budget이 여유있을때도 있음 test case를 통해 확인함.
if d:
min_value = d.pop(0)
if min_value <= budget:
budget -= min_value
answer += 1
else:
break
else:
break
return answer
12 changes: 12 additions & 0 deletions 3차/류동준_최대공약수와-최소공배수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def gcd(a,b):
mod = a % b;
while(mod > 0):
a = b
b = mod
Comment on lines +4 to +5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python의 멋진 기능

Suggested change
a = b
b = mod
a, b = b, mod

mod = a % b
return b


def solution(n, m):
value = gcd(n,m)
return [value, n *m / value]
Comment on lines +1 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 주말에 설명 부탁드립니다.

13 changes: 13 additions & 0 deletions 3차/류동준_콜라츠-추축.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def solution(num):
answer = 0
while(num!=1):
if answer > 500:
answer = -1
break
if num % 2 == 0:
num = num / 2
else:
num = (num * 3) + 1
answer += 1

return answer
Empty file.
7 changes: 7 additions & 0 deletions 3차/류동준_행렬의-덧셈.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# import numpy as np
def solution(arr1, arr2):
for i in range(len(arr1)):
for j in range(len(arr1[i])):
arr1[i][j] += arr2[i][j]
return arr1
# return np.add(np.asarray(arr1),np.asarray(arr2)).tolist()