let fs = require('fs');
let path = process.platform === 'linux' ? '/dev/stdin' : './data.txt';
let input = fs.readFileSync(path).toString().trim();
function solve(input) {
let number = Number(input);
if (number === 1) {
return 1;
} else {
number--;
let count = 1;
let temp = count * 6;
while (true) {
if (number - temp <= 0) {
return ++count;
} else {
count++;
let temp2 = count * 6;
temp += temp2;
}
}
}
}
console.log(solve(input));
์ค์~ python์ผ๋ก ํ ๋๋ ํผ์ ๋ชปํ์๋ ๊ฒ ๊ธฐ์ต์ด ๋๋๋ฐ, javascript๋ก๋ ํผ์ ํ์๋ค~
const input = require('fs').readFileSync('/dev/stdin');
let range = 1, block = 1;
while (block < input) {
block += 6 * range;
range++;
}
console.log(range);
๋ฌธ์ ํ ๋, while ์์ ์กฐ๊ฑด์์ ๋ค๋ฅธ ํ์ด์ฒ๋ผ ์ฃผ๋ ๊ฑธ ์ผํ ์๊ฐํ๋๋ฐ...
๊ฐ์ ๋ต์ ๋ธ ์ ๋ต์์๋ ์ด๋ ๊ฒ ๊ฐ๊ฒฐํ ์ ์๋ค๋ ๊ฒ์ ์์ผ ๋ค์ ๋๋๋ค. ๋์ค์ ๋๋ ๋ ๊ฐ๊ฒฐํ๊ณ ๊น๋ํ๊ณ ์ง๊ด์ ์ธ ์ฝ๋๋ฅผ ์ธ ์ ์์ ๊ฒ์ด๋ค.
๊ณ์ ๋ฐฐ์ฐ๊ณ ๋ฐฐ์ฐ์.
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 2869 (0) | 2022.05.19 |
---|---|
[JS] 1193 (0) | 2022.05.18 |
[JS] 1712 (0) | 2022.05.18 |
[JS] 1316 (0) | 2022.05.18 |
[JS] 2941 (0) | 2022.05.18 |