https://school.programmers.co.kr/learn/courses/30/lessons/17687
function solution(n, t, m, p) {
const max = m * (t - 1) + p;
const answer = [];
let numbers = "";
let value = 0;
while (numbers.length < max) numbers += (value++).toString(n);
let i = 0;
while (answer.length < t) {
if ((i % m) + 1 === p) answer.push(numbers[i]);
i++;
}
return answer.join("").toUpperCase();
}
// 제너레이터 활용
function solution(n, t, m, p) {
const program = (function* (n) {
let value = 0;
while (true) {
const numbers = [...value.toString(n)];
for (let i = 0; i < numbers.length; i++)
yield numbers[i].toString().toUpperCase();
value++;
}
})(n);
const output = [];
let i = 0;
while (output.length < t) {
const { value } = program.next();
if (i++ % m === p - 1) output.push(value);
}
return output.join("");
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (완전탐색) Lv 2. 모음사전 (0) | 2023.02.23 |
---|---|
[Programmers] (2022 KAKAO BLIND RECRUITMENT) Lv 2. 주차 요금 계산 (0) | 2023.02.22 |
[Programmers] Lv 2. 할인 행사 (0) | 2023.02.20 |
[Programmers] Lv 2. 땅따먹기 (0) | 2023.02.18 |
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [3차] 압축 (0) | 2023.02.17 |
댓글