-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
The head ref may contain hidden characters: "3\uCC28/\uB958\uB3D9\uC900"
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저... 너무 급하신 거같아요 3차/류동준_핸드폰-번호-가리기.py 이건 내용이 없어욬ㅋㅋㅋㅋㅋ
a = b | ||
b = mod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python의 멋진 기능
a = b | |
b = mod | |
a, b = b, mod |
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 주말에 설명 부탁드립니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다.
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) |
There was a problem hiding this comment.
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.sub
의 count
는 0
일때, 모든 값을 바꿔버려요 한마디로 0 = 무한대
라는 의미가 된거죠.
즉, 빈 값일때, 제한을 두지 않는 것처럼요.
즉, 정상적으로 동작시키기 위해서는 저의 얇팍한 지식으로는 아래와 같이 변경해야해요.
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 형태가 어렵다면 분리해야해요. 아래처럼요.
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) |
도움이 되었으면 좋겠어요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확실히 형이나 동건이 코드를 보면 제가 활용할 수 있는 기술들(ex : 정규표현식, 다양한 파이썬 내장함수 등)을 잘 모르거나 알아도 막상 문제를 보면 당황해서 적용을 못하거나 생각도 못했다는 걸 느낄 수 있습니다.
고생하셨습니다.
문제 제목
[카카오 인턴] 키패드 누르기
문제 출제 의도
문제 해결 전략
채점 결과
사용한 테스트 케이스
기본
소요 시간
2시간이 넘어서 그냥 접근법을 위해 검색을 통해 이해 했음.
문제 제목
최대 공약수와 최소 공배수
문제 출제 의도
최대 공약수와 최소 공배수를 구하는데있어 여러 naive한 방안과 효율적인 방안을 찾는것
문제 해결 전략
채점 결과
사용한 테스트 케이스
기본
소요 시간
10분
기타
최대 공약수 최소 공배수를 구할때 참고했던 자료입니다.
참고하면 좋을 자료
문제 제목
콜라츠 추측
문제 출제 의도
문제를 잘읽고 하라는것을 잘 구현했는가..?
문제 해결 전략
문제에서 이미 답을 구하기 위한 작업 프로세스를 준다.
채점 결과
사용한 테스트 케이스
기본
소요 시간
3분
문제 제목
핸드폰 번호 가리기
문제 출제 의도
문제 해결 전략.
출제의도에 적어둔 2가지 방법으로 풀수 있다고 생각함.
아 그리고 python의 regex의 sub를 이용한 문자열 치환은 string 클래스에서 제공하는 replace보다 일반적으로 훨씬 빠르다고 합니다.
채점 결과
사용한 테스트 케이스
기본
소요 시간
10분
기타
코드에도 주석을 통해 적어두었지만 regex를 이용하여 치환할때 특정케이스에 문제가 발생하는데
이유를 찾아내기도했고 나름의 수정 코드를 넣었지만 특정 케이스가 통과되지 못하는 경우가 있었음.
문제 제목
행렬의 덧셈
문제 출제 의도
이중 for문의 데이터에 대한 접근을 할수 있는지
문제 해결 전략.
채점 결과
사용한 테스트 케이스
기본
소요 시간
10분
기타
당연하지만 numpy를 이용한 add는 시간 메모리 측면에서 더 오래걸리기만 하였다.
문제 제목
예산
문제 출제 의도
문제 해결 전략.
한정된 budget에서 최대 효율을 뽑는 경우를 구하기 위하여 생각할수있는 방안으로
여기서 task당 cost는 각 부서별 신청 금액과 같습니다.
채점 결과
사용한 테스트 케이스
기본
소요 시간
15분
기타
처음엔 budget이 가장 작은 cost보다 작아질때까지 빼기만했는데
특정 케이스에서의 런타임 error가있었다.
고민을 조금하다가 테스트 케이스에는 모든 task를 처리했을 경우도 고려하여 데이터가 주어졌다는점을 알 수 있었다.