From 30b5e51459aed27e2a923b3a44205beed62059f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=EC=A3=BC?= Date: Sat, 4 Oct 2025 14:26:43 +0900 Subject: [PATCH 1/4] =?UTF-8?q?1~3=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/problem1.js | 28 ++++++++++++++++++++++++++-- src/problem2.js | 12 ++++++++++-- src/problem3.js | 12 ++++++++++-- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/problem1.js b/src/problem1.js index 9a14f2c..c46cb16 100644 --- a/src/problem1.js +++ b/src/problem1.js @@ -1,6 +1,30 @@ function problem1(pobi, crong) { - var answer; - return answer; + if (pobi[1] - pobi[0] !== 1 || crong[1] - crong[0] !== 1) { + return -1; + } + const pobiMax = Math.max(maxValue(String(pobi[0])), maxValue(String(pobi[1]))); + const crongMax = Math.max(maxValue(String(crong[0])), maxValue(String(crong[1]))); + + if(pobiMax > crongMax){ + return 1; + } else if(pobiMax < crongMax){ + return 2; + } else { + return 0; + } + +} + +function maxValue(page){ + let sum = 0; + let mul = 1; + const pageStr = page.split(""); + for(let i of pageStr){ + sum += Number(i); + mul *= Number(i); + } + return Math.max(sum, mul); } + module.exports = problem1; diff --git a/src/problem2.js b/src/problem2.js index cebd07c..31646dd 100644 --- a/src/problem2.js +++ b/src/problem2.js @@ -1,6 +1,14 @@ function problem2(cryptogram) { - var answer; - return answer; + const stack = []; + let secret = cryptogram.split(""); + for( let i = 0; i < secret.length; i++){ + stack.push(secret[i]); + if(stack.length >= 2 && stack[stack.length - 1] === stack[stack.length - 2]){ + stack.pop(); + stack.pop(); + } + } + return stack.join(""); } module.exports = problem2; diff --git a/src/problem3.js b/src/problem3.js index 1baed28..512f39f 100644 --- a/src/problem3.js +++ b/src/problem3.js @@ -1,6 +1,14 @@ function problem3(number) { - var answer; - return answer; + let clap = 0; + for(let i=1; i<=number; i++){ + let str = String(i).split(""); + for(let j of str){ + if(j === "3" || j === "6" || j === "9"){ + clap+=1; + } + } + } + return clap; } module.exports = problem3; From 05b891f36aeb12d624479acd88c16a8ff250ce50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=EC=A3=BC?= Date: Sun, 5 Oct 2025 14:15:47 +0900 Subject: [PATCH 2/4] 4-5 --- src/problem4.js | 22 ++++++++++++++++++++-- src/problem5.js | 9 ++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/problem4.js b/src/problem4.js index ee1d3bd..a1f5f3f 100644 --- a/src/problem4.js +++ b/src/problem4.js @@ -1,6 +1,24 @@ function problem4(word) { - var answer; - return answer; + let result = ''; + + for (let i = 0; i < word.length; i++) { + const char = word[i]; + const charCode = char.charCodeAt(0); + + if (charCode >= 65 && charCode <= 90) { + const newCharCode = 90 + 65 - charCode; + result += String.fromCharCode(newCharCode); + } + else if (charCode >= 97 && charCode <= 122) { + const newCharCode = 122 + 97 - charCode; + result += String.fromCharCode(newCharCode); + } + else { + result += char; + } + } + return result; } + module.exports = problem4; diff --git a/src/problem5.js b/src/problem5.js index 9368e87..28ff163 100644 --- a/src/problem5.js +++ b/src/problem5.js @@ -1,5 +1,12 @@ function problem5(money) { - var answer; + const change = [50000, 10000, 5000, 1000, 500, 100, 50, 10, 1]; + let answer = Array(change.length).fill(0); + let i = 0; + while(money !== 0){ + answer[i] = parseInt(money/change[i]); + money = money % change[i]; + i++; + } return answer; } From 835acf6c2703fc06e30c905f0fe5e508e425dcce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=EC=A3=BC?= Date: Sat, 11 Oct 2025 16:52:31 +0900 Subject: [PATCH 3/4] 6 --- src/problem6.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/problem6.js b/src/problem6.js index 3f842b5..e314aca 100644 --- a/src/problem6.js +++ b/src/problem6.js @@ -1,6 +1,26 @@ function problem6(forms) { - var answer; - return answer; + let errorEmail = []; + + for(let i=0;i Date: Sat, 11 Oct 2025 19:12:56 +0900 Subject: [PATCH 4/4] 7 --- src/problem7.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/problem7.js b/src/problem7.js index ee1bb9d..970ce6d 100644 --- a/src/problem7.js +++ b/src/problem7.js @@ -1,6 +1,57 @@ function problem7(user, friends, visitors) { - var answer; - return answer; + const friendMap = new Map(); + const scoreMap = new Map(); + const myFriends = new Set(); + + function addFriendship(a, b) { + if (!friendMap.has(a)) friendMap.set(a, new Set()); + friendMap.get(a).add(b); + } + + for (const [idA, idB] of friends) { + addFriendship(idA, idB); + addFriendship(idB, idA); + + if (idA === user) myFriends.add(idB); + if (idB === user) myFriends.add(idA); + } + + for (const visitorId of visitors) { + if (visitorId === user || myFriends.has(visitorId)) { + continue; + } + + const currentScore = scoreMap.get(visitorId) || 0; + scoreMap.set(visitorId, currentScore + 1); + } + + const userFriends = friendMap.get(user) || new Set(); + + for (const friendId of userFriends) { + const potentialFriends = friendMap.get(friendId) || new Set(); + + for (const candidateId of potentialFriends) { + if (candidateId === user || myFriends.has(candidateId)) { + continue; + } + + const currentScore = scoreMap.get(candidateId) || 0; + scoreMap.set(candidateId, currentScore + 10); + } + } + + const sortedCandidates = Array.from(scoreMap.entries()) + .filter(([_, score]) => score > 0) + .sort(([idA, scoreA], [idB, scoreB]) => { + if (scoreA !== scoreB) { + return scoreB - scoreA; + } + return idA.localeCompare(idB); + }) + .map(([id, _]) => id) + .slice(0, 5); + + return sortedCandidates; } module.exports = problem7;