Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

문제 풀이 추가 #65

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

Merged
codeisneverodd merged 6 commits into codeisneverodd:main from minjongbaek:main
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
13 changes: 13 additions & 0 deletions level-2/k-진수에서-소수-개수-구하기.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function isPrime(number) {
Copy link
Owner

@codeisneverodd codeisneverodd Jul 11, 2022

Choose a reason for hiding this comment

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

멋진 풀이네요! 해설 상단에 다른 파일들과 같이 주석 부탁드립니다 :)

if (number < 2) return false;
for (let i = 2; i * i <= number; i += 1) {
if (number % i === 0) {
return false;
}
}
return true;
}

function solution(n, k) {
return (n).toString(k).split('0').filter((number) => isPrime(+number)).length;
}
27 changes: 27 additions & 0 deletions level-2/방금-그곡.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function convertString(m) {
Copy link
Owner

@codeisneverodd codeisneverodd Jul 11, 2022

Choose a reason for hiding this comment

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

풀이 잘 보았습니다! 파일명을 '[3차]-방금그곡' 으로 변경하고, 해설 상단에도 주석을 추가해주세요!

return m
.replace(/C#/g, 'c')
.replace(/D#/g, 'd')
.replace(/F#/g, 'f')
.replace(/G#/g, 'g')
.replace(/A#/g, 'a');
}

function solution(m, musicinfos) {
const listenSound = convertString(m);

const map = new Map();
for (const info of musicinfos) {
const [start, finish, title, _score] = info.split(',');
const duration = ((+finish.slice(0, 2) * 60) + (+finish.slice(3, 5))) - ((+start.slice(0, 2) * 60) + (+start.slice(3, 5)));
Copy link
Owner

@codeisneverodd codeisneverodd Jul 11, 2022

Choose a reason for hiding this comment

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

+finish 와 같은 구문은 문자를 숫자로 변환하기 위한 것인가요? 명시적이지 않은 타입 변환으로 보여서 혼란이 있을 수 있을 것 같다고 생각합니다 :)

Copy link
Contributor Author

@minjongbaek minjongbaek Jul 11, 2022

Choose a reason for hiding this comment

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

해당 식에 괄호가 많아져서 Number 함수를 사용하지 않았었습니다. 말씀 듣고 코드를 확인해보니 산술 연산자들 때문에 +와 같은 암묵적 타입 변환이 코드를 읽는데 번잡스러울 것 같습니다. 명시적으로 타입 변환하게끔 수정해두었습니다.


const score = convertString(_score);
const playScore = score.repeat(Math.ceil(duration / score.length)).slice(0, duration);
if (playScore.includes(listenSound)) {
map.set(title, {score, playScore});
}
}

const filter = [...map.keys()].sort((a,b) => map.get(b).playScore.length - map.get(a).playScore.length);
return filter.length >= 1 ? filter[0] : '(None)';
}
62 changes: 62 additions & 0 deletions level-2/빛의-경로-사이클.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const DX = [-1, 1, 0, 0];
Copy link
Owner

@codeisneverodd codeisneverodd Jul 11, 2022

Choose a reason for hiding this comment

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

해당 해설에도 주석 부탁드립니다!

const DY = [0, 0, -1, 1];

function solution(grid) {
const answer = [];
const visited = Array.from({ length: grid.length }, () => []).map((v) => {
for (let i = 0; i < grid[0].length; i += 1) {
v.push(new Array(4).fill(false));
}
return v
});

for (let x = 0; x < grid.length; x += 1) {
for (let y = 0; y < grid[0].length; y += 1) {
for (let d = 0; d < 4; d += 1) {
if (!visited[x][y][d]) {
const stack = [];
stack.push([x, y, d]);

let cnt = 0;
while (stack.length !== 0) {
const [currentX, currentY, currentD] = stack.pop();
if (!visited[currentX][currentY][currentD]) {
visited[currentX][currentY][currentD] = true;
cnt += 1;

const [nextX, nextY] = getNextXY(currentX, currentY, currentD, grid.length, grid[0].length);
const nextD = getNextD(grid[nextX][nextY], currentD)

stack.push([nextX, nextY, nextD])
}

}
answer.push(cnt);
}
}
}
}
return answer.sort((a, b) => a - b);
}


function getNextXY(x, y, d, xLength, yLength) {
x += DX[d];
y += DY[d];

if (x < 0) x = xLength - 1;
if (x >= xLength) x = 0;
if (y < 0) y = yLength - 1;
if (y >= yLength) y = 0;

return [x, y];
}

function getNextD(command, d) {
if (command === 'L') {
d = [2, 3, 1, 0][d]
} else if (command === 'R') {
d = [3, 2, 0, 1][d]
}
return d
}

AltStyle によって変換されたページ (->オリジナル) /