Skip to content

리드미 변경 로직 변경 및 api 생성 함수 추가 #101

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
merged 20 commits into from
Sep 12, 2022
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .github/workflows/update-README.yml
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ on:
push:
branches:
- main
- feat/id-based-parsing
pull_request:
branches:
- main
197 changes: 139 additions & 58 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api.json

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.
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.
Original file line number Diff line number Diff line change
@@ -2,38 +2,38 @@
//더 좋은 풀이가 존재할 수 있습니다.
//정답 1(🎩 refactor 220425) - codeisneverodd
function solution(n) {
let answer = "";
let answer = '';
for (let i = 0; i < n; i++) {
answer += i % 2 === 0 ? "수" : "박";
answer += i % 2 === 0 ? '수' : '박';
}
return answer;
}

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

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

//정답 4 - prove-ability
function solution(n) {
let answer = '';
answer = "수박".repeat(n / 2)
if(n % 2 !== 0) answer += '수'
answer = '수박'.repeat(n / 2);
if (n % 2 !== 0) answer += '수';
return answer;
}

//정답 5 - yongchanson
function solution(n) {
return "수박".repeat(n / 2) + "수".repeat(n % 2);
return '수박'.repeat(n / 2) + '수'.repeat(n % 2);
}
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.
123 changes: 0 additions & 123 deletions level-1/키패드-누르기.js

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.
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.
16 changes: 16 additions & 0 deletions level-3/2-x-n-타일링&12900&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - jaewon1676
function solution(n) {
let dp = [0, 1, 2] // n이 1, 2일때는 바로 답을 출력,
if (n>2){ // n이 3 이상이면 필요한 만큼의 수 까지만 수를 만들어준다.
for (let i=3; i<=n; i++){
dp.push((dp[i-1] + dp[i-2]) % 1000000007);
}
}
return dp[n]
}
/*
n이 1일땐 1, 2일땐 2, 3일땐 3, 4일땐 5 . . 의 식이 보인다.
n = (n - 1) + (n - 2)의 식으로 구할 수 있고,
제한 사항을 주의해서 풀어보자. */
39 changes: 39 additions & 0 deletions level-3/N-Queen&12952&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(n) {
/*
1. 0번째 행에 0번째 queen을 놓는다.
2. 그 다음 행의 퀸은 이전 퀸들의 범위와 겹치지 않는 곳에 놓는다. 퀸은 한 행에 반드시 하나 두어야한다.
3. 마지막 열까지 도달하면 성공으로 간주하고 answer에 1을 더한다.
4. 0번째 queen의 위치를 바꿔가며 모두 시도한다.
4. 단, 체스판은 일차원 배열로 선언하고 index = 행, 값 = 열 로 생각한다.
*/
let answer = 0;
const canBePlacedOn = (chess, currentRow) => {
//해당 행에 둔 queen이 유효한지
for (let prevRow = 0; prevRow < currentRow; prevRow++) {
const onDiagonal = currentRow - prevRow === Math.abs(chess[currentRow] - chess[prevRow])
const onStraight = chess[prevRow] === chess[currentRow]
if (onDiagonal || onStraight) return false
}
return true
}
const placeQueen = (chess, currentRow) => {
//queen을 배치하다가 끝 행에 도착하면 1을 리턴, 도착하지 못하면 0을 리턴하여, 재귀적으로 모든 경우를 합하여 리턴
let count = 0
if (currentRow === chess.length) return 1
for (let currentQueen = 0; currentQueen < n; currentQueen++) {
//queen을 우선 배치한 후 가능한지 살펴본다.
chess[currentRow] = currentQueen
if (canBePlacedOn(chess, currentRow)) count += placeQueen(chess, currentRow + 1)
}
return count
}
for (let firstQueen = 0; firstQueen < n; firstQueen++) {
const chess = new Array(n).fill(-1)
chess[0] = firstQueen
answer += placeQueen(chess, 1)
}
return answer;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions level-3/입국심사&43238&.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(n, times) {
//최소로 걸릴 수 있는 시간 left, 최대로 걸릴 수 있는 시간 right
let [left, right] = [1, Math.max(...times) * n];
while (left <= right) {
const mid = Math.floor((left + right) / 2);
const sum = times.reduce((acc, time) => acc + Math.floor(mid / time), 0);
//sum은 mid 시간 동안 처리 할 수 있는 사람의 수
if (sum < n) {
left = mid + 1;
} else {
right = mid - 1;
}
}
// left 가 right를 넘어갔다는 것은 left가 n보다 크거나 같아져서 n명을 수용할 수 최소값이 되있다는 것이다.
return left;
}
19 changes: 0 additions & 19 deletions level-3/입국심사.js

This file was deleted.

9 changes: 2 additions & 7 deletions level-4/단어-퍼즐.js → level-4/단어-퍼즐&12983&.js
Original file line number Diff line number Diff line change
@@ -19,18 +19,13 @@ function solution(strs, t) {
minCountToIndex[currentIndex] = 1;
} else {
//앞쪽에 남은 것이 있다면, 현재 검사중이 영역까지 필요한 조각 수는, 지금까지 구한 최소 값과 지금 구한 값 중 최소값
minCountToIndex[currentIndex] = Math.min(
minCountToIndex[currentIndex],
minCountToIndex[frontLength - 1] + 1
);
minCountToIndex[currentIndex] = Math.min(minCountToIndex[currentIndex], minCountToIndex[frontLength - 1] + 1);
}
}
}
}
//마지막 영역이 Infinity 이면 만들기 불가능한 단어, 아니라면 마지막 영역의 값을 리턴
return minCountToIndex[tLength - 1] === Infinity
? -1
: minCountToIndex[tLength - 1];
return minCountToIndex[tLength - 1] === Infinity ? -1 : minCountToIndex[tLength - 1];
}

//리드미 테스트용 코멘트
33 changes: 33 additions & 0 deletions utils/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import fs from 'fs';
const splitCodeToSolutions = code => {
if (code === undefined) return [];
const solutions = code.split(/\/\/[ ]*정답/);
return [solutions[0], ...solutions.slice(1).map(solution => '//' + solution)];
};

export const generateAPI = () => {
try {
const api = [1, 2, 3, 4, 5].flatMap(level =>
fs
.readdirSync(`level-${level}`)
.filter(name => name !== '00-해답-예시.js')
.map(file => {
const [name, id, extension] = file.split('&');
const code = splitCodeToSolutions(fs.readFileSync(`level-${level}/${file}`, 'utf-8'));
return {
id,
name: name.replaceAll('-', ' '),
fileName: file,
level,
code: code[0] + code[1],
link: `https://school.programmers.co.kr/learn/courses/30/lessons/${id}`,
};
})
);
fs.writeFileSync('api.json', JSON.stringify(api));
return api;
} catch (e) {
console.log('Making API ERROR: ' + e);
return [];
}
};
Loading
Oops, something went wrong.