Skip to content

[ryan-dia] level 2 문제 풀이 추가 #121

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
33 changes: 32 additions & 1 deletion level-2/k진수에서-소수-개수-구하기&92335&.js
Original file line number Diff line number Diff line change
@@ -20,4 +20,35 @@ function solution(n, k) {
// .split('0') // 0을 기준으로 나눕니다.
// .filter((number) => isPrime(+number)).length // 소수가 아닌 요소를 걸러낸 후에 개수를 셉니다.
return (n).toString(k).split('0').filter((number) => isPrime(+number)).length;
}
}


// 정답 2 - ryna-dia

function solution(n, k) {
const numbers = n;
const antilogarithm = k;
const NumbersChangedAntilogarithm = numbers.toString(antilogarithm);
const result = selectPrimeNotIncludeZero(NumbersChangedAntilogarithm);

return result.length;
}

function selectPrimeNotIncludeZero(numbers, numbersWithoutZero = '') {
return [...numbers].reduce((acc, cur, index, arr) => {
if (cur !== '0') numbersWithoutZero += cur;
if (cur === '0' || index === arr.length - 1) {
if (isPrime(Number(numbersWithoutZero))) acc.push(numbersWithoutZero);
numbersWithoutZero = '';
}
return acc;
}, []);
}

function isPrime(num) {
if (!num || num === 1) return false;
for (let i = 2; i <= Math.sqrt(num); i++) {
if (!(num % i)) return false;
}
return true;
}
21 changes: 21 additions & 0 deletions level-2/프린터&42587&.js
Original file line number Diff line number Diff line change
@@ -134,3 +134,24 @@ class Queue {
return this.rear - this.front
}
}

// 정답 6 ryan-dia

function solution(priorities, location, result = 0) {
const queue = priorities.map((p, i) => ({ priority: p, index: i }));

while (queue.length > 0) {
const current = queue.shift();
const higherPriority = queue.some((d) => d.priority > current.priority);

if (higherPriority) {
queue.push(current);
continue;
}
result += 1;
if (current.index === location) {
return result;
}
}
}