Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions docs/PROBLEM2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

암호문을 좋아하는 괴짜 개발자 브라운이 이번에는 중복 문자를 이용한 새로운 암호를 만들었다. 예를 들어 "browoanoommnaon"이라는 암호문은 다음과 같은 순서로 해독할 수 있다.

1. "browoanoommnaon"
2. "browoannaon"
3. "browoaaon"
4. "browoon"
연속되는 문자가 있으면 삭제
1. "browoanoommnaon" 여기서 중복되는 oo, mm을 삭제
2. "browoannaon" nn 삭제
3. "browoaaon" aa 삭제
4. "browoon" oo 삭제
5. "brown"

임의의 문자열 cryptogram이 매개변수로 주어질 때, 연속하는 중복 문자들을 삭제한 결과를 return 하도록 solution 메서드를 완성하라.
Expand All @@ -21,4 +22,4 @@
| ----------------- | ------- |
| "browoanoommnaon" | "brown" |
| "zyelleyz" | "" |

zyelleyz는 단계로 수행하면 모두가 동일한 문장이기에 전부 삭제
34 changes: 33 additions & 1 deletion src/problem1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
function problem1(pobi, crong) {
var answer;

var [pobi_max, crong_max] = [pobi, crong].map(pages => {
if (pages[0] + 1 == pages[1]) {
let check = pages.map(page => {
let num = page.toString().split("").map(Number);
let add = 0;
let gob = 1;

for (let i=0; i < num.length; i++){
add += num[i];
gob *= num[i];
}

return Math.max(add, gob);
})

return Math.max(...check)
}
else return -1;
})

if (pobi_max == -1 || crong_max == -1) {
answer = -1;
}
else if(pobi_max > crong_max) {
answer = 1;
}
else if (pobi_max < crong_max) {
answer = 2;
}
else answer = 0;

return answer;
}

module.exports = problem1;
module.exports = problem1;
13 changes: 13 additions & 0 deletions src/problem2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
function problem2(cryptogram) {
var answer;

let i = 0;
do {
var check = cryptogram;
if (cryptogram[i] == cryptogram[i+1]) {
cryptogram = cryptogram.replace(cryptogram[i] + cryptogram[i+1], "");
i = 0;
}
else i++;
} while(i != cryptogram.length)

answer = cryptogram;

return answer;
}

Expand Down
18 changes: 18 additions & 0 deletions src/problem3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
function problem3(number) {
var answer;
var count = 1;
var clap = 0;
var clap_num = [3, 6, 9];

while (count <= number) {
let check = count.toString().split("").map(Number);
for (let i=0; i < check.length; i++) {
for (let j=0; j < 3; j++) {
if (check[i] == clap_num[j]) {
clap += 1;
}
}
}
count += 1;
}

answer = clap;

return answer;
}

Expand Down
26 changes: 25 additions & 1 deletion src/problem4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
function problem4(word) {
var answer;
var answer = "";

var frog_word = new Map([
["a", "z"], ["b", "y"], ["c", "x"], ["d", "w"], ["e", "v"],
["f", "u"], ["g", "t"], ["h", "s"], ["i", "r"], ["j", "q"],
["k", "p"], ["l", "o"], ["m", "n"], ["n", "m"], ["o", "l"],
["p", "k"], ["q", "j"], ["r", "i"], ["s", "h"], ["t", "g"],
["u", "f"], ["v", "e"], ["w", "d"], ["x", "c"], ["y", "b"],
["z", "a"]
])

for ( let i=0; i < word.length; i++) {
let change = word[i].toLowerCase();


if (frog_word.has(change)) {
if (word[i] !== word[i].toLowerCase()) {
let ToBig = frog_word.get(change);
answer += ToBig.toUpperCase();
}
else answer += frog_word.get(change);
}
else answer += " ";
}

return answer;
}

Expand Down
9 changes: 8 additions & 1 deletion src/problem5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
function problem5(money) {
var answer;
var answer = [];
var won = [50000, 10000, 5000, 1000, 500, 100, 50, 10, 1];
var cash;
answer = won.map(div => {
cash = Math.floor(money / div);
money = money % div;
return cash
})
return answer;
}

Expand Down
35 changes: 34 additions & 1 deletion src/problem6.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
function compare_make(name) {
let result = [];

for (let i=0; i < name.length - 1; i++) {
for (let j=2; j <= name.length; j++) {
result.push(name.slice(i, i+j));
}
}

return result;
}

function problem6(forms) {
var answer;
var answer = [];
var data = new Map(forms);
var back = [];
var check = false;

for ( let [email, nick] of data ) {
let compare = compare_make(nick);
for (let i=0; i < compare.length; i++) {
for (let [email_compare, nick_compare] of data) {
if (email_compare != email && nick_compare.includes(compare[i])) {
check = true;
}
}
}
if (check) {
back.push(email);
}
check = false;
}

answer = back.sort();

return answer;
}

Expand Down
65 changes: 64 additions & 1 deletion src/problem7.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
function problem7(user, friends, visitors) {
var answer;
var answer = [];

// 친구 이름 찾기
var user_friends = friends
.filter(([x, y]) => ( user == x || user == y ))
.map(([x, y]) => (x === user ? y : x));

// 친구의 친구 찾기
var fri_friends = [];
friends.forEach(find_fri => {
for (let i=0; i < user_friends.length; i++) {
if (find_fri.includes(user_friends[i]) && !find_fri.includes(user) ) {
fri_friends.push(find_fri[0] !== user_friends[i] ? find_fri[0] : find_fri[1]);
}
}
});

// 친구의 친구 점수
var count_fri_friends = new Map();
fri_friends.forEach(x => {
let count = fri_friends.filter(check => check === x && !user_friends.includes(x))
.length;
if (!count_fri_friends.has(x)) {
count_fri_friends.set(x, count*10);
}
});

// 방문자 점수
var count_visit = new Map();
visitors.forEach(x => {
let count = visitors.filter(check => check === x && !user_friends.includes(x))
.length;
if (!count_visit.has(x)) {
count_visit.set(x, count);
}
})

// 총합
for (let [key, value] of count_visit) {
if (!user_friends.includes(key)){
if (count_fri_friends.has(key)) {
count_fri_friends.set(key, count_fri_friends.get(key) + value);
}else {
count_fri_friends.set(key, value);
}
}
}

// 정렬
var sorted = [...count_fri_friends.entries()].sort((x, y) => {
if (x[1] === y[1]) {
return x[0].localeCompare(y[0]);
}
else return y[1] - x[1];
})

// 마지막으로 친구의 친구 map과 방문자 카운트 합치기

for (let [key, value] of sorted) {
answer.push(key);
}

answer = answer.slice(0,5);

return answer;
}

Expand Down