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

3차/류동준 #22

wants to merge 3 commits into from

Conversation

rdj94
Copy link
Collaborator

@rdj94 rdj94 commented Sep 13, 2020

문제 제목

[카카오 인턴] 키패드 누르기

문제 출제 의도

  1. Dist를 어떠한 형태로 구할수 있는지.
  2. String +=할수 있는지.

문제 해결 전략

  1. 왼쪽 숫자 배열과 오른쪽 숫자 배열은 단순히 양손의 위치를 변경해주고 answer에 'L' or 'R'을 더 해주면됩니다.
  2. num이 가운데 숫자 배열에 속하는 값일때 양손에서 num과 dist가 얼마나 차이나는지를 구하여 더 작은 값의 경우를 선택하면됩니다.

채점 결과

image

사용한 테스트 케이스

기본

소요 시간

2시간이 넘어서 그냥 접근법을 위해 검색을 통해 이해 했음.

문제 제목

최대 공약수와 최소 공배수

문제 출제 의도

최대 공약수와 최소 공배수를 구하는데있어 여러 naive한 방안과 효율적인 방안을 찾는것

문제 해결 전략

  1. naive 하게는 a,b의 최대 공약수는 a,b 둘중 작은값까지만 range로 나머지 연산하면서 둘이 나누어 떨어질때 최대 공약수로 반환할수 있음.

채점 결과

image

사용한 테스트 케이스

기본

소요 시간

10분

기타

최대 공약수 최소 공배수를 구할때 참고했던 자료입니다.
참고하면 좋을 자료

문제 제목

콜라츠 추측

문제 출제 의도

문제를 잘읽고 하라는것을 잘 구현했는가..?

문제 해결 전략

문제에서 이미 답을 구하기 위한 작업 프로세스를 준다.

채점 결과

image

사용한 테스트 케이스

기본

소요 시간

3분

문제 제목

핸드폰 번호 가리기

문제 출제 의도

  1. 문자열의 slice 활용 할수 있는가
  2. regex를 활용할수 있는가

문제 해결 전략.

출제의도에 적어둔 2가지 방법으로 풀수 있다고 생각함.

  1. slice를 활용한 방안은 단순히 뒤에서 4번째숫자까지의 배열 index들의 값을 *로 채우면됩니다.
  2. 정규 표현식 regex의 경우 re.sub 함수가 있고 string 클래스의 replcae함수 둘다 (찾을값,바꿀값,반복 횟수)에 대한 arg를 지원합니다.
    아 그리고 python의 regex의 sub를 이용한 문자열 치환은 string 클래스에서 제공하는 replace보다 일반적으로 훨씬 빠르다고 합니다.

채점 결과

image

사용한 테스트 케이스

기본

소요 시간

10분

기타

코드에도 주석을 통해 적어두었지만 regex를 이용하여 치환할때 특정케이스에 문제가 발생하는데
이유를 찾아내기도했고 나름의 수정 코드를 넣었지만 특정 케이스가 통과되지 못하는 경우가 있었음.

문제 제목

행렬의 덧셈

문제 출제 의도

이중 for문의 데이터에 대한 접근을 할수 있는지

문제 해결 전략.

  1. 단순히 이중 for문을 이용한 순회에서 두 arr1,arr2 가 가지는 인덱스의 value를 더해주면 됩니다.
  2. 선형대수에 특화된 numpy로 계산해보는것도 나쁘지 않다.

채점 결과

image

사용한 테스트 케이스

기본

소요 시간

10분

기타

당연하지만 numpy를 이용한 add는 시간 메모리 측면에서 더 오래걸리기만 하였다.

문제 제목

예산

문제 출제 의도

  1. Dynamic Programming 인데 최적해를 구하는 방법을 아세요?
  2. 코드적인 접근에서 한정된 budget을 활용하기위해 어떤 task의 cost를 고려하는게 좋을지

문제 해결 전략.

한정된 budget에서 최대 효율을 뽑는 경우를 구하기 위하여 생각할수있는 방안으로

  1. 가장 적은 cost의 task를 뽑아서 먼저 처리해간다면 가장 많은 task를 처리할 수 있습니다.
    여기서 task당 cost는 각 부서별 신청 금액과 같습니다.

채점 결과

image

사용한 테스트 케이스

기본

소요 시간

15분

기타

처음엔 budget이 가장 작은 cost보다 작아질때까지 빼기만했는데
특정 케이스에서의 런타임 error가있었다.
고민을 조금하다가 테스트 케이스에는 모든 task를 처리했을 경우도 고려하여 데이터가 주어졌다는점을 알 수 있었다.

@rdj94 rdj94 self-assigned this Sep 13, 2020
@rdj94 rdj94 added the 3차 label Sep 13, 2020
Copy link
Collaborator

@Sotaneum Sotaneum left a comment

Choose a reason for hiding this comment

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

저... 너무 급하신 거같아요 3차/류동준_핸드폰-번호-가리기.py 이건 내용이 없어욬ㅋㅋㅋㅋㅋ

Comment on lines +4 to +5
a = b
b = mod
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

Comment on lines +1 to +12
def gcd(a,b):
mod = a % b;
while(mod > 0):
a = b
b = mod
mod = a % b
return b


def solution(n, m):
value = gcd(n,m)
return [value, n *m / value]
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Collaborator

@Sotaneum Sotaneum left a comment

Choose a reason for hiding this comment

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

수고하셨습니다.

Comment on lines +4 to +11
tmp = list(phone_number)
tmp[:len(tmp) -4 ] = '*' * (len(tmp) -4)
# or 이거 왜 안되는지 모르겠음 9번 케이스가 틀린다
# data = re.sub('[\s]','*',phone_number,len(phone_number)-4) 일때 9번이 통과는함 근데 re.sub('[\s\d]','*',phone_number,len(phone_number)-4) 일때는 안함 ㅅㅂ
# data = re.sub('[\d\s]','*',phone_number,len(phone_number)-4)
# print(data)
# return data
return ''.join(tmp)
Copy link
Collaborator

Choose a reason for hiding this comment

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

확실하지 않지만 9번 케이스는 phone_number의 길이가 4일때 인 것 같아요.

phone_number : "0000"  # 결과는 0000이여야함

data = re.sub('[\s]','*',phone_number,len(phone_number)-4)

위 정규식은 띄어쓰기만 검출해요, 그러니까 결국에는 replace되는게 없는거죠. 그래서 9번 케이스의 길이가 4개짜리는 정답이 된거죠 ( 그대로 출력되니까요 )

만약 \s 형태로 쓰고 싶다면 [\s\S]으로 변경하면 아마 아래와 같은 결과를 얻을 수 있었을 거예요.
[\s\S]는 모든 걸 검출하겠다는 의미거든요.


data = re.sub('[\d\s]','*',phone_number,len(phone_number)-4)

이건 9번을 통과할 수 없었던 이유는 아래에서 설명할게요
[\d\s]는 숫자와, 띄어쓰기를 검출하겠다는 의미예요. 그래서 어쩌다가 \d 값때문에 9번을 제외하고 제대로 작성되었던 거죠. \s는 불필요해요.

문제 특성상, 문자열에서 알파벳이 아닌 숫자만 검출하는게 맞는 것 같아요. 그래서 아래처럼 \d만 검출하는게 더 맞는 것 같아요.

data = re.sub('(\d)','*',phone_number,len(phone_number)-4)

위에 처럼요. 그럼 이제 9번을 제외한 나머지 값이 맞을거예요.


9번까지 맞기 위해서는 re.sub에 대해 알아봐야해요.

re.subcount0일때, 모든 값을 바꿔버려요 한마디로 0 = 무한대 라는 의미가 된거죠.
즉, 빈 값일때, 제한을 두지 않는 것처럼요.

즉, 정상적으로 동작시키기 위해서는 저의 얇팍한 지식으로는 아래와 같이 변경해야해요.

Suggested change
tmp = list(phone_number)
tmp[:len(tmp) -4 ] = '*' * (len(tmp) -4)
# or 이거 왜 안되는지 모르겠음 9번 케이스가 틀린다
# data = re.sub('[\s]','*',phone_number,len(phone_number)-4) 일때 9번이 통과는함 근데 re.sub('[\s\d]','*',phone_number,len(phone_number)-4) 일때는 안함 ㅅㅂ
# data = re.sub('[\d\s]','*',phone_number,len(phone_number)-4)
# print(data)
# return data
return ''.join(tmp)
return re.sub('(\d)','*',phone_number, -1 if len(phone_number)-4 == 0 else len(phone_number)-4)

true if else false 형태가 어렵다면 분리해야해요. 아래처럼요.

Suggested change
tmp = list(phone_number)
tmp[:len(tmp) -4 ] = '*' * (len(tmp) -4)
# or 이거 왜 안되는지 모르겠음 9번 케이스가 틀린다
# data = re.sub('[\s]','*',phone_number,len(phone_number)-4) 일때 9번이 통과는함 근데 re.sub('[\s\d]','*',phone_number,len(phone_number)-4) 일때는 안함 ㅅㅂ
# data = re.sub('[\d\s]','*',phone_number,len(phone_number)-4)
# print(data)
# return data
return ''.join(tmp)
if len(phone_number) == 4:
return phone_number
return re.sub('(\d)','*',phone_number, len(phone_number) - 4)

도움이 되었으면 좋겠어요

Copy link
Collaborator

@0113bernoyoun 0113bernoyoun left a comment

Choose a reason for hiding this comment

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

확실히 형이나 동건이 코드를 보면 제가 활용할 수 있는 기술들(ex : 정규표현식, 다양한 파이썬 내장함수 등)을 잘 모르거나 알아도 막상 문제를 보면 당황해서 적용을 못하거나 생각도 못했다는 걸 느낄 수 있습니다.
고생하셨습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants