Skip to content

Commit 36d3bee

Browse files
Merge pull request #101 from codeisneverodd/v0.4.0
리드미 변경 로직 변경 및 api 생성 함수 추가
2 parents 5e9192e + 39adf0a commit 36d3bee

File tree

148 files changed

+308
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+308
-297
lines changed

.github/workflows/update-README.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
push:
88
branches:
99
- main
10+
- feat/id-based-parsing
1011
pull_request:
1112
branches:
1213
- main

README.md

Lines changed: 139 additions & 58 deletions

api.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

level-1/수박수박수박수박수박수.js renamed to level-1/수박수박수박수박수박수?&12922&.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@
22
//더 좋은 풀이가 존재할 수 있습니다.
33
//정답 1(🎩 refactor 220425) - codeisneverodd
44
function solution(n) {
5-
let answer = "";
5+
let answer = '';
66
for (let i = 0; i < n; i++) {
7-
answer += i % 2 === 0 ? "수" : "박";
7+
answer += i % 2 === 0 ? '수' : '박';
88
}
99
return answer;
1010
}
1111

1212
//정답 2 - chaerin-dev
1313
function solution(n) {
1414
// "수박"을 n번 반복한 문자열의 0번 인덱스부터 n만큼 추출해서 반환
15-
return "수박".repeat(n).substr(0, n);
15+
return '수박'.repeat(n).substr(0, n);
1616
}
1717

1818
//정답 3 - jaewon1676
1919
function solution(n) {
20-
let str = "";
20+
let str = '';
2121
for (let i = 0; i < n; i++) {
2222
// 삼항 연산자와 +로 문자열을 붙여주어 추가.
23-
i % 2 == 0 ? (str = str + "수") : (str = str + "박");
23+
i % 2 == 0 ? (str = str + '수') : (str = str + '박');
2424
}
2525
return str;
2626
}
2727

2828
//정답 4 - prove-ability
2929
function solution(n) {
3030
let answer = '';
31-
answer = "수박".repeat(n / 2)
32-
if(n % 2 !== 0) answer += '수'
31+
answer = '수박'.repeat(n / 2);
32+
if (n % 2 !== 0) answer += '수';
3333
return answer;
3434
}
3535

3636
//정답 5 - yongchanson
3737
function solution(n) {
38-
return "수박".repeat(n / 2) + "수".repeat(n % 2);
38+
return '수박'.repeat(n / 2) + '수'.repeat(n % 2);
3939
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

level-1/키패드-누르기.js

Lines changed: 0 additions & 123 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

level-3/2-x-n-타일링&12900&.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - jaewon1676
4+
function solution(n) {
5+
let dp = [0, 1, 2] // n이 1, 2일때는 바로 답을 출력,
6+
if (n>2){ // n이 3 이상이면 필요한 만큼의 수 까지만 수를 만들어준다.
7+
for (let i=3; i<=n; i++){
8+
dp.push((dp[i-1] + dp[i-2]) % 1000000007);
9+
}
10+
}
11+
return dp[n]
12+
}
13+
/*
14+
n이 1일땐 1, 2일땐 2, 3일땐 3, 4일땐 5 . . 의 식이 보인다.
15+
n = (n - 1) + (n - 2)의 식으로 구할 수 있고,
16+
제한 사항을 주의해서 풀어보자. */

level-3/N-Queen&12952&.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - codeisneverodd
4+
function solution(n) {
5+
/*
6+
1. 0번째 행에 0번째 queen을 놓는다.
7+
2. 그 다음 행의 퀸은 이전 퀸들의 범위와 겹치지 않는 곳에 놓는다. 퀸은 한 행에 반드시 하나 두어야한다.
8+
3. 마지막 열까지 도달하면 성공으로 간주하고 answer에 1을 더한다.
9+
4. 0번째 queen의 위치를 바꿔가며 모두 시도한다.
10+
4. 단, 체스판은 일차원 배열로 선언하고 index = 행, 값 = 열 로 생각한다.
11+
*/
12+
let answer = 0;
13+
const canBePlacedOn = (chess, currentRow) => {
14+
//해당 행에 둔 queen이 유효한지
15+
for (let prevRow = 0; prevRow < currentRow; prevRow++) {
16+
const onDiagonal = currentRow - prevRow === Math.abs(chess[currentRow] - chess[prevRow])
17+
const onStraight = chess[prevRow] === chess[currentRow]
18+
if (onDiagonal || onStraight) return false
19+
}
20+
return true
21+
}
22+
const placeQueen = (chess, currentRow) => {
23+
//queen을 배치하다가 끝 행에 도착하면 1을 리턴, 도착하지 못하면 0을 리턴하여, 재귀적으로 모든 경우를 합하여 리턴
24+
let count = 0
25+
if (currentRow === chess.length) return 1
26+
for (let currentQueen = 0; currentQueen < n; currentQueen++) {
27+
//queen을 우선 배치한 후 가능한지 살펴본다.
28+
chess[currentRow] = currentQueen
29+
if (canBePlacedOn(chess, currentRow)) count += placeQueen(chess, currentRow + 1)
30+
}
31+
return count
32+
}
33+
for (let firstQueen = 0; firstQueen < n; firstQueen++) {
34+
const chess = new Array(n).fill(-1)
35+
chess[0] = firstQueen
36+
answer += placeQueen(chess, 1)
37+
}
38+
return answer;
39+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

level-3/입국심사&43238&.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - codeisneverodd
4+
function solution(n, times) {
5+
//최소로 걸릴 수 있는 시간 left, 최대로 걸릴 수 있는 시간 right
6+
let [left, right] = [1, Math.max(...times) * n];
7+
while (left <= right) {
8+
const mid = Math.floor((left + right) / 2);
9+
const sum = times.reduce((acc, time) => acc + Math.floor(mid / time), 0);
10+
//sum은 mid 시간 동안 처리 할 수 있는 사람의 수
11+
if (sum < n) {
12+
left = mid + 1;
13+
} else {
14+
right = mid - 1;
15+
}
16+
}
17+
// left 가 right를 넘어갔다는 것은 left가 n보다 크거나 같아져서 n명을 수용할 수 최소값이 되있다는 것이다.
18+
return left;
19+
}

level-3/입국심사.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

level-4/단어-퍼즐.js renamed to level-4/단어-퍼즐&12983&.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,13 @@ function solution(strs, t) {
1919
minCountToIndex[currentIndex] = 1;
2020
} else {
2121
//앞쪽에 남은 것이 있다면, 현재 검사중이 영역까지 필요한 조각 수는, 지금까지 구한 최소 값과 지금 구한 값 중 최소값
22-
minCountToIndex[currentIndex] = Math.min(
23-
minCountToIndex[currentIndex],
24-
minCountToIndex[frontLength - 1] + 1
25-
);
22+
minCountToIndex[currentIndex] = Math.min(minCountToIndex[currentIndex], minCountToIndex[frontLength - 1] + 1);
2623
}
2724
}
2825
}
2926
}
3027
//마지막 영역이 Infinity 이면 만들기 불가능한 단어, 아니라면 마지막 영역의 값을 리턴
31-
return minCountToIndex[tLength - 1] === Infinity
32-
? -1
33-
: minCountToIndex[tLength - 1];
28+
return minCountToIndex[tLength - 1] === Infinity ? -1 : minCountToIndex[tLength - 1];
3429
}
3530

3631
//리드미 테스트용 코멘트

utils/api.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import fs from 'fs';
2+
const splitCodeToSolutions = code => {
3+
if (code === undefined) return [];
4+
const solutions = code.split(/\/\/[ ]*/);
5+
return [solutions[0], ...solutions.slice(1).map(solution => '//' + solution)];
6+
};
7+
8+
export const generateAPI = () => {
9+
try {
10+
const api = [1, 2, 3, 4, 5].flatMap(level =>
11+
fs
12+
.readdirSync(`level-${level}`)
13+
.filter(name => name !== '00-해답-예시.js')
14+
.map(file => {
15+
const [name, id, extension] = file.split('&');
16+
const code = splitCodeToSolutions(fs.readFileSync(`level-${level}/${file}`, 'utf-8'));
17+
return {
18+
id,
19+
name: name.replaceAll('-', ' '),
20+
fileName: file,
21+
level,
22+
code: code[0] + code[1],
23+
link: `https://school.programmers.co.kr/learn/courses/30/lessons/${id}`,
24+
};
25+
})
26+
);
27+
fs.writeFileSync('api.json', JSON.stringify(api));
28+
return api;
29+
} catch (e) {
30+
console.log('Making API ERROR: ' + e);
31+
return [];
32+
}
33+
};

0 commit comments

Comments
 (0)