Skip to content

Commit db2925a

Browse files
feat: level 0 풀이 완료
1 parent 10a301f commit db2925a

19 files changed

+211
-65
lines changed

level-0/OX퀴즈&120907&.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(quiz) {
5+
return quiz.map(q => {
6+
const [formula, answer] = q.split('=');
7+
return eval(formula) === +answer ? 'O' : 'X';
8+
});
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(lines) {
5+
const visited = lines.reduce((a, [x, y]) => {
6+
for (let i = Math.min(x, y) + 1; i <= Math.max(x, y); i++) a[i] = a[i] ? a[i] + 1 : 1;
7+
return a;
8+
}, {});
9+
10+
return Object.values(visited).filter(v => v > 1).length;
11+
}
+19-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(polynomial) {
5+
const countX = x => {
6+
const count = x.replaceAll('x', '');
7+
return count === '' ? 1 : +count;
8+
};
9+
10+
const count = polynomial
11+
.split(' + ')
12+
.reduce((a, c) => (c.includes('x') ? { ...a, x: a.x + countX(c) } : { ...a, num: a.num + +c }), {
13+
x: 0,
14+
num: 0,
15+
});
16+
17+
const x = count.x > 0 ? `${count.x > 1 ? count.x : ''}x` : '';
18+
const num = count.num > 0 ? '' + count.num : '';
19+
const plus = x !== '' && num !== '' ? ' + ' : '';
20+
21+
return x + plus + num;
22+
}

level-0/등수-매기기&120882&.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(score) {
5+
const avgs = score.map(([a, b]) => (a + b) / 2);
6+
const avgRank = [...avgs]
7+
.sort((a, b) => b - a)
8+
.map((avg, i) => ({ avg, rank: i + 1 }))
9+
.map((a, i, arr) => (i > 0 && a.avg === arr[i - 1].avg ? { ...a, rank: arr[i - 1].rank } : a));
10+
11+
return avgs.map(_avg => avgRank.find(({ avg }) => _avg === avg).rank);
12+
}
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(id_pw, db) {
5+
const [id, pw] = id_pw;
6+
if (!db.find(([_id]) => _id === id)) return 'fail';
7+
return db.find(([_id, _pw]) => _id === id && _pw === pw) ? 'login' : 'wrong pw';
8+
}
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(my_string) {
5+
return eval(my_string);
6+
}

level-0/분수의-덧셈&120808&.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(denum1, num1, denum2, num2) {
5+
const denum = denum2 * num1 + denum1 * num2;
6+
const num = num1 * num2;
7+
const getGCD = (a, b) => (b === 0 ? a : getGCD(b, a % b));
8+
const gcd = getGCD(denum, num);
9+
return [denum / gcd, num / gcd];
10+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(sides) {
5+
const min = Math.min(...sides);
6+
const max1 = Math.max(...sides);
7+
const max2 = min + max1 - 1;
8+
return max2 - (max1 - min);
9+
}
10+
11+
//정답 2 - codeisneverodd
12+
function solution(sides) {
13+
return Math.min(...sides) * 2 - 1;
14+
}

level-0/안전지대&120866&.js

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(board) {
5+
const isBombNearby = (r, c) => {
6+
const nearby = [
7+
[-1, -1],
8+
[-1, 0],
9+
[-1, 1],
10+
[0, -1],
11+
[0, 1],
12+
[1, -1],
13+
[1, 0],
14+
[1, 1],
15+
];
16+
17+
const isInBoard = (r, c) => r >= 0 && r < board.length && c >= 0 && c < board.length;
18+
19+
return nearby.some(([dR, dC]) => isInBoard(r + dR, c + dC) && board[r + dR][c + dC] === 1);
20+
};
21+
22+
let count = 0;
23+
24+
for (let r = 0; r < board.length; r++) {
25+
for (let c = 0; c < board.length; c++) {
26+
if (board[r][c] !== 1 && !isBombNearby(r, c)) count += 1;
27+
}
28+
}
29+
return count;
30+
}
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(num, total) {
5+
const numArr = Array.from({ length: num }, (_, i) => i);
6+
const sum = numArr.reduce((a, c) => a + c);
7+
return numArr.map(n => n - (sum - total) / num);
8+
}

level-0/옹알이&120956&.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(babbling) {
5+
const convertPWordsToNum = word => {
6+
const pWords = ['aya', 'ye', 'woo', 'ma'];
7+
return pWords.reduce((result, pWord, i) => result.replaceAll(pWord, i), word);
8+
};
9+
const canPronounce = word => {
10+
const result = convertPWordsToNum(word);
11+
return !/[^\d]/.test(result) && [...result].every((num, i) => i + 1 > result.length || num !== result[i + 1]);
12+
};
13+
14+
return babbling.filter(b => canPronounce(b)).length;
15+
}

level-0/저주의-숫자-3&120871&.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
44
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
5+
let num = 0;
6+
let count = 0;
7+
8+
while (count < n) {
9+
num += 1;
10+
if (!('' + num).includes('3') && num % 3 !== 0) count += 1;
11+
}
12+
13+
return num;
14+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
const readline = require('readline');
5+
const rl = readline.createInterface({
6+
input: process.stdin,
7+
output: process.stdout,
8+
});
9+
10+
let input = [];
11+
12+
rl.on('line', function (line) {
13+
input = line.split(' ');
14+
}).on('close', function () {
15+
for (let i = 1; i <= +input[0]; i++) console.log('*'.repeat(i));
16+
});
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
const readline = require('readline');
5-
const rl = readline.createInterface({
6-
input: process.stdin,
7-
output: process.stdout,
8-
});
9-
10-
let input = [];
11-
12-
rl.on('line', function (line) {
13-
input = line.split(' ');
14-
}).on('close', function () {
15-
for (let i = 1; i <= +input[0]; i++) console.log('*'.repeat(i));
16-
});
4+
function solution(dots) {
5+
const xDots = dots.flatMap(([x, y]) => x);
6+
const yDots = dots.flatMap(([x, y]) => y);
7+
const width = Math.max(...xDots) - Math.min(...xDots);
8+
const height = Math.max(...yDots) - Math.min(...yDots);
9+
return width * height;
10+
}

level-0/진료순서-정하기&120835&.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
44
function solution(emergency) {
5-
const sorted = emergency.map((e, i) => [e, i + 1]).sort((a, b) => b[0] - a[0]);
6-
return emergency.map(e => sorted.find(s => s[0] === e)[1]);
5+
const sorted = [...emergency].sort((a, b) => b - a);
6+
return emergency.map(e => sorted.findIndex(s => s === e) + 1);
77
}

level-0/치킨-쿠폰&120884&.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(chicken) {
5+
const order = coupons => {
6+
if (coupons < 10) return 0;
7+
const service = Math.floor(coupons / 10);
8+
return service + order(service + (coupons % 10));
9+
};
10+
return order(chicken);
11+
}
+40-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(keyinput, board) {
5+
const moves = {
6+
up: [0, 1],
7+
down: [0, -1],
8+
left: [-1, 0],
9+
right: [1, 0],
10+
};
11+
const [rangeX, rangeY] = [Math.floor(board[0] / 2), Math.floor(board[1] / 2)];
12+
13+
return keyinput
14+
.map(key => moves[key])
15+
.reduce(
16+
([x, y], [mX, mY]) => (Math.abs(x + mX) > rangeX || Math.abs(y + mY) > rangeY ? [x, y] : [x + mX, y + mY]),
17+
[0, 0]
18+
);
19+
}
20+
21+
//정답 2 - codeisneverodd
22+
//명령형
23+
function solution(keyinput, board) {
24+
const moves = {
25+
up: [0, 1],
26+
down: [0, -1],
27+
left: [-1, 0],
28+
right: [1, 0],
29+
};
30+
const [rangeX, rangeY] = [Math.floor(board[0] / 2), Math.floor(board[1] / 2)];
31+
32+
let pos = [0, 0];
33+
34+
keyinput
35+
.map(key => moves[key])
36+
.forEach(move => {
37+
if (Math.abs(move[0] + pos[0]) > rangeX || Math.abs(move[1] + pos[1]) > rangeY) return;
38+
pos[0] += move[0];
39+
pos[1] += move[1];
40+
});
41+
42+
return pos;
43+
}

level-0/특이한-정렬&120880&.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(numlist, n) {
5+
return numlist.sort((a, b) => {
6+
const [aDiff, bDiff] = [Math.abs(a - n), Math.abs(b - n)];
7+
if (aDiff === bDiff) return b - a;
8+
return aDiff - bDiff;
9+
});
10+
}

level-0/평행&120875&.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
//https://github.com/codeisneverodd/programmers-coding-test
22
//완벽한 정답이 아닙니다.
33
//정답 1 - codeisneverodd
4-
function solution(n) {
5-
//프로그래머스에 제출하여 통과된 함수를 복사 붙여넣기 해주세요!
6-
}
4+
function solution(dots) {
5+
const getInclination = ([[x1, y1], [x2, y2]]) => (x2 !== x1 ? (y2 - y1) / (x2 - x1) : Infinity);
6+
const isParallel = (line1, line2) => getInclination(line1) === getInclination(line2);
7+
8+
return dots.some(dot => {
9+
const line1 = [dots[0], dot];
10+
const line2 = dots.filter(dot => !line1.includes(dot));
11+
return isParallel(line1, line2);
12+
})
13+
? 1
14+
: 0;
15+
}

0 commit comments

Comments
 (0)