-
Notifications
You must be signed in to change notification settings - Fork 0
Prgmrs test 1 #16
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
lgyn10
wants to merge
5
commits into
main
Choose a base branch
from
prgmrs-test-1
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
Prgmrs test 1 #16
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,41 @@ | ||
| // https://school.programmers.co.kr/learn/courses/30/lessons/92335 | ||
|
|
||
| //! ver 1. 최초 코드 | ||
| function primeCnt(n: number, k: number) { | ||
| // 소수 판별 함수 | ||
| const isPrime = (num: number) => { | ||
| if (num === 1) return false; | ||
| for (let i = 2; i * i <= num; i++) if (num % i === 0) return false; | ||
| return true; | ||
| }; | ||
|
|
||
| const convertedNum = n.toString(k); // k진수로 변환 | ||
| const splitedConvertedNum = convertedNum.split('0'); // 조건에 맞게 분리 | ||
|
|
||
| const ans = splitedConvertedNum.filter((v) => { | ||
| if (v === '') return false; | ||
| if (isPrime(parseInt(v, 10))) return true; | ||
| else return false; | ||
| }); | ||
| return ans.length; | ||
| } | ||
|
|
||
| //! ver 2. 개선 코드 | ||
| // filter 함수의 콜백 함수를 리펙토링함 | ||
| const primeCnt2 = (n: number, k: number) => { | ||
| // 소수 판별 함수 | ||
| const isPrime = (num: number) => { | ||
| if (num === 1) return false; | ||
| for (let i = 2; i * i <= num; i++) if (num % i === 0) return false; | ||
| return true; | ||
| }; | ||
| // 코어 로직 | ||
| const convertedNum = n.toString(k); // k진수로 변환 | ||
| const splitedConvertedNum = convertedNum.split('0'); // 조건에 맞게 분리 | ||
| return splitedConvertedNum.filter((v) => isPrime(parseInt(v, 10)) && v !== '').length; | ||
| }; | ||
|
|
||
| console.log(primeCnt(437674, 3)); // 3 | ||
| console.log(primeCnt(110011, 10)); // 2 | ||
| console.log(primeCnt2(437674, 3)); // 3 | ||
| console.log(primeCnt2(110011, 10)); // 2 |
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,22 @@ | ||
| // https://school.programmers.co.kr/learn/courses/30/lessons/181903 | ||
|
|
||
| //! ver 1. 최초 코드 | ||
| function restIdxString(q, r, code) { | ||
| return [...code] | ||
| .filter((v, i) => { | ||
| if (i % q === r) return true; | ||
| }) | ||
| .join(''); | ||
| } | ||
|
|
||
| //! ver 2. 개선 코드 | ||
| // 불필요한 if문 제거 | ||
| const restIdxString2 = (q, r, code) => { | ||
| return [...code].filter((_, i) => i % q === r).join(''); | ||
| }; | ||
|
|
||
| //| 입출력 예 | ||
| console.log(restIdxString(3, 1, 'qjnwezgrpirldywt')); // "jerry" | ||
| console.log(restIdxString(1, 0, 'programmers')); // "programmers" | ||
| console.log(restIdxString2(3, 1, 'qjnwezgrpirldywt')); // "jerry" | ||
| console.log(restIdxString2(1, 0, 'programmers')); // "programmers" |
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,43 @@ | ||
| // 마라톤 | ||
| // 한 명만 미완주 | ||
|
|
||
| //! ver 1. 최초 코드 | ||
| function dnfPerson(participant, completion) { | ||
| // 동명 이인 없을 경우 => 시간 효율 측면에서 불필요 | ||
| // const firstLoop = participant.filter(name => { | ||
| // if(!completion.some(v=> v === name)) return true | ||
| // }) | ||
| // if(firstLoop.length !== 0) return firstLoop.at(0) | ||
|
|
||
| // 동명이인도 있는 경우 | ||
| const prtMap = new Map(); | ||
| const comMap = new Map(); | ||
| participant.forEach((name) => prtMap.set(name, (prtMap.get(name) ?? 0) + 1)); | ||
| completion.forEach((name) => comMap.set(name, (comMap.get(name) ?? 0) + 1)); | ||
|
|
||
| return participant | ||
| .filter((name) => { | ||
| if (prtMap.get(name) !== comMap.get(name)) return true; | ||
| }) | ||
| .at(0); | ||
| } | ||
|
|
||
| //! ver 2. 개선 코드 | ||
| // filter의 콜백 함수 단순화 | ||
| const dnfPerson2 = (participant, completion) => { | ||
| const prtMap = new Map(); | ||
| const comMap = new Map(); | ||
| participant.forEach((name) => prtMap.set(name, (prtMap.get(name) ?? 0) + 1)); | ||
| completion.forEach((name) => comMap.set(name, (comMap.get(name) ?? 0) + 1)); | ||
|
|
||
| // 코어 로직 한 줄 정리 | ||
| return participant.filter((name) => prtMap.get(name) !== comMap.get(name)).at(0); | ||
| }; | ||
|
|
||
| console.log(dnfPerson(['leo', 'kiki', 'eden'], ['eden', 'kiki'])); // "leo" | ||
| console.log(dnfPerson(['marina', 'josipa', 'nikola', 'vinko', 'filipa'], ['josipa', 'filipa', 'marina', 'nikola'])); // "vinko" | ||
| console.log(dnfPerson(['mislav', 'stanko', 'mislav', 'ana'], ['stanko', 'ana', 'mislav'])); // "mislav" | ||
|
|
||
| console.log(dnfPerson2(['leo', 'kiki', 'eden'], ['eden', 'kiki'])); // "leo" | ||
| console.log(dnfPerson2(['marina', 'josipa', 'nikola', 'vinko', 'filipa'], ['josipa', 'filipa', 'marina', 'nikola'])); // "vinko" | ||
| console.log(dnfPerson2(['mislav', 'stanko', 'mislav', 'ana'], ['stanko', 'ana', 'mislav'])); // "mislav" |
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,21 @@ | ||
| // https://school.programmers.co.kr/learn/courses/30/lessons/42862 | ||
|
|
||
| //! ver 1. 최초 코드 | ||
| // 정답률 90% | ||
| function 체육복(n, lost, reserve) { | ||
| const finalLost = lost.filter((v) => { | ||
| if (reserve.some((e) => e === v)) { | ||
| reserve.splice(reserve.indexOf(v), 1); | ||
| } else if (reserve.some((e) => e === v - 1)) { | ||
| reserve.splice(reserve.indexOf(v - 1), 1); | ||
| } else if (reserve.some((e) => e === v + 1)) { | ||
| reserve.splice(reserve.indexOf(v + 1), 1); | ||
| } else return true; | ||
| }); | ||
| return n - finalLost.length; | ||
| } | ||
|
|
||
| //| 입출력 예 | ||
| console.log(체육복(5, [2, 4], [1, 3, 5])); // 5 | ||
| console.log(체육복(5, [2, 4], [3])); // 4 | ||
| console.log(체육복(3, [3], [1])); // 2 | ||
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,19 @@ | ||
| // https://school.programmers.co.kr/learn/courses/30/lessons/87946 | ||
|
|
||
| // 탐험 시작 위한 `최소 필요 피로도` | ||
| // 탐험 끝났을 때 소모되는 `소모 피로도` | ||
|
|
||
| //! ver 1. 최초 코드 - 못 품 | ||
|
Owner
Author
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. 다시 풀어보기 |
||
| function maxDungeon(k, dungeons) { | ||
| dungeons.sort((a, b) => b[0] - b[1] - (a[0] - a[1])); | ||
| const a = dungeons.filter((v) => { | ||
| k - v[1]; | ||
| if (k >= 0) return true; | ||
| }); | ||
| console.log(dungeons); | ||
| console.log(a); | ||
| return a.length; | ||
| } | ||
|
|
||
| //! ver 2. 최초 코드 - 재풀이 | ||
| const maxDungeon2 = (k, dungeons) => {}; | ||
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.
다시 풀어보기