Skip to content

Commit 0670f63

Browse files
committed
103차 2번 문제풀이
1 parent ace50b1 commit 0670f63

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const filePath =
5+
process.platform === "linux"
6+
? "/dev/stdin"
7+
: path.join(__dirname, "input.txt");
8+
9+
const input = fs.readFileSync(filePath, "utf8").toString().trim();
10+
11+
function solution(input) {
12+
const sugar = input;
13+
let [bag3, bag5] = [0, 0];
14+
bag5 = Math.floor(sugar / 5);
15+
bag3 = (sugar - bag5 * 5) / 3;
16+
17+
while (bag5 >= 0) {
18+
if (bag3 === Math.floor(bag3)) return bag5 + bag3;
19+
20+
if (bag3 % 3 !== 0) {
21+
--bag5;
22+
bag3 = (sugar - bag5 * 5) / 3;
23+
}
24+
}
25+
return -1;
26+
}
27+
28+
console.log(solution(input));

0 commit comments

Comments
 (0)