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
38 changes: 37 additions & 1 deletion src/problem1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
function problem1(pobi, crong) {
var answer;
return answer;
var pobi_max, crong_max ;

if (pobi[0] % 2 == 0 || pobi[1] % 2 == 1 || crong[0] % 2 == 0 || crong[1] % 2 == 1 || pobi[1] - pobi[0] != 1 || crong[1] - crong[0] != 1) {
return -1;
}

pobi_1 = pobi[0].toString(); pobi_2 = pobi[1].toString();
crong_1 = crong[0].toString(); crong_2 = crong[1].toString();
pobi_max = Math.max(Math.max(plus(pobi_1), plus(pobi_2)), Math.max(multi(pobi_1), multi(pobi_2)))
crong_max = Math.max(Math.max(plus(crong_1), plus(crong_2)), Math.max(multi(crong_1), multi(crong_2)))

if (pobi_max > crong_max) {
return 1;
} else if (pobi_max < crong_max) {
return 2;
} else {
return 0;
}
}

function plus(now_num) {
var res = 0;

for (i = 0;i < now_num.length;i++) {
res += parseInt(now_num.substring(i, i + 1));
}

return res;
}

function multi(now_num) {
var res = 1;

for (i = 0;i < now_num.length;i++) {
res *= parseInt(now_num.substring(i, i + 1));
}

return res;
}
module.exports = problem1;
20 changes: 18 additions & 2 deletions src/problem2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
function problem2(cryptogram) {
var answer;
return answer;
var pre_str = cryptogram ;
var now_str ;
while (1) {
now_str = search_str(pre_str)
if (now_str == pre_str || now_str.length == 0) {
return now_str ;
}
pre_str = now_str;
}
}

function search_str(now_str) {
for (var i = 0;i < now_str.length - 1;i++) {
if (now_str[i] == now_str[i + 1]) {
return now_str.slice(0, i) + now_str.slice(i + 2);
}
}
return now_str;
}

module.exports = problem2;
14 changes: 12 additions & 2 deletions src/problem3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
function problem3(number) {
var answer;
return answer;
var res = 0;
for (var i = 1;i <= number;i++) {
now_str = i.toString();
res += search_369(now_str, '3');
res += search_369(now_str, '6');
res += search_369(now_str, '9');
}
return res;
}

function search_369(str, num) {
return str.split(num).length - 1 ;
}

module.exports = problem3;
17 changes: 15 additions & 2 deletions src/problem4.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
function problem4(word) {
var answer;
return answer;
var res_str = '';
var now_ascii = 0;
for (i = 0;i < word.length;i++) {
if (word[i] == ' ') {
res_str += ' ';
} else {
now_ascii = word.charCodeAt(i);
if (now_ascii < 91) {
res_str += String.fromCharCode(90 - (now_ascii - 65));
} else {
res_str += String.fromCharCode(122 - (now_ascii - 97));
}
}
}
return res_str ;
}

module.exports = problem4;
13 changes: 11 additions & 2 deletions src/problem5.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
function problem5(money) {
var answer;
return answer;
var res_list = [0, 0, 0, 0, 0, 0, 0, 0, 0] ;
var money_list = {0 : 50000, 1 : 10000, 2 : 5000, 3 : 1000, 4 : 500, 5 : 100, 6 : 50, 7 : 10, 8 : 1} ;
var now_won = 0 ;

for (i = 0;i < 9;i++) {
now_won = money_list[i] ;
res_list[i] = Math.floor(money / now_won) ;
money %= now_won ;
}

return res_list ;
}

module.exports = problem5;
31 changes: 29 additions & 2 deletions src/problem6.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
function problem6(forms) {
var answer;
return answer;
var dupli_list = new Array(forms.length).fill(0) ;
var res_list = [] ;
for (var i = 0;i < forms.length;i++) {
for (var j = i + 1;j < forms.length;j++) {
if (dupli_search(forms[i][1], forms[j][1]) == true) {
if (dupli_list[i] == 0) {
res_list.push(forms[i][0]);
dupli_list[i] = 1;
}
if (dupli_list[j] == 0) {
res_list.push(forms[j][0]);
dupli_list[j] = 1;
}
}
}
}
res_list.sort()
return res_list;
}

function dupli_search(str1, str2) {
for (var i = 0;i < str1.length - 1;i++) {
for (var j = 0;j < str2.length - 1;j++) {
if (str1.slice(i, i + 2) == str2.slice(j, j + 2)) {
return true ;
}
}
}
return false ;
}

module.exports = problem6;
51 changes: 49 additions & 2 deletions src/problem7.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
function problem7(user, friends, visitors) {
var answer;
return answer;
let user_friends = [];
let score_dict = {};

for (let i = 0; i < friends.length; i++) {
let f0 = friends[i][0];
let f1 = friends[i][1];
if (f0 === user) {
user_friends.push(f1);
} else if (f1 === user) {
user_friends.push(f0);
}
}

for (let i = 0; i < friends.length; i++) {
let f0 = friends[i][0];
let f1 = friends[i][1];
if (f0 === user || f1 === user) {continue;}

if (user_friends.includes(f0)) {
if (score_dict[f1]) {
score_dict[f1] -= 10;
} else {
score_dict[f1] = -10;
}
} else if (user_friends.includes(f1)) {
if (score_dict[f0]) {
score_dict[f0] -= 10;
} else {
score_dict[f0] = -10;
}
}
}

for (let i = 0; i < visitors.length; i++) {
let now_visitors = visitors[i];
if (!user_friends.includes(now_visitors)) {
if (score_dict[now_visitors]) {
score_dict[now_visitors] -= 1;
} else {
score_dict[now_visitors] = -1;
}
}
}

let res_list = Object.entries(score_dict)
.sort((a, b) => a[1] - b[1])
.map(item => item[0]) ;

return res_list;
}

module.exports = problem7;