-
Notifications
You must be signed in to change notification settings - Fork 9
[김주혜] 17주차 60059번 과제 제출합니다. #115
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
Open
rlawngP91
wants to merge
1
commit into
kth990303:main
Choose a base branch
from
rlawngP91:60059_jhkim
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import numpy as np | ||
|
|
||
| #key와 lock의 각각의 요소를 합친 배열의 결과 - answer | ||
| #answer의 배열의 요소가 모두 1이 아니면 false | ||
| def checklock(answer): | ||
| for i in answer: | ||
| for j in i: | ||
| if j!=1: | ||
| return False | ||
| return True | ||
|
Comment on lines
+5
to
+10
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자주 쓰는 코드묶음을 함수화 해두는 것은 나중에 디버깅할 때에도 훨씬 편하겠죠 👍🏼 |
||
|
|
||
| #lock을 key의 size-1만큼 더해서 확장시킨 배열로 만들고 가장자리부분 0으로 초기화 | ||
| #key와 lock의 블록이 하나씩, 두개씩, 세개씩, ... 점점 많아지게 겹쳐서 더한 후 | ||
| #(겹쳐지는 부분이 많아지다가 모든 key요소와 모든 lock의 요소가 합쳐진 다음 다시 겹쳐지는 부분이 줄어듬) | ||
| #원래의 lock size에 맞게 배열 slice - checklock함수로 unlock할 수 있는지 확인 | ||
| def unlock(answerkey, lock): | ||
| N = len(lock) | ||
| M = len(answerkey) | ||
| #확장 | ||
| lock = np.pad(lock, (M-1, M-1)) | ||
|
|
||
| #확장시킨 배열에 key를 오른쪽 아래방향으로 한칸씩 옮겨가면서 더하고 원래의 lock size에 맞게 배열 slice | ||
| newM = N+M-1 | ||
| for i in range(newM): | ||
| for j in range(newM): | ||
| resultlock = lock.copy() | ||
| resultlock[i:i+M,j:j+M] = lock[i:i+M,j:j+M] + answerkey[:][:] | ||
| if checklock(resultlock[M-1:M+N-1,M-1:M+N-1]): | ||
| return True | ||
|
|
||
| return False | ||
| def solution(key, lock): | ||
| #numpy array로 변경 | ||
| answerkey = np.array(key) | ||
| lock = np.array(lock) | ||
|
|
||
| flag = False | ||
|
|
||
| for i in range(4): | ||
| # i*90만큼 key회전 -> 0, 90, 180, 270만 수행 | ||
| answerkey = np.rot90(answerkey, i) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 회전은 |
||
| flag = unlock(answerkey, lock) | ||
| if flag == True: | ||
| break | ||
| return flag | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
프로그래머스에서는
numpy라이브러리가 사용 가능한가보네요! 외부 라이브러리라서, 기업 코테를 준비하신다면numpy없이 문제를 풀어보시는 것도 추천드립니다