const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = Number(fs.readFileSync(path).toString());
function solve(input) {
let firstInput = input;
let i = 0;
while (true) {
let numberSum = Math.floor(input / 10) + (input % 10);
input = (input % 10) * 10 + (numberSum % 10);
i++;
if (input === firstInput) {
return i;
}
}
}
console.log(solve(input));
์ด ๋ฌธ์ ๋ ์ฒ์์ ๋ฌธ์์ด๋ก ์ฒ๋ฆฌํด์ ํ๋ค๊ฐ ์ด์ํ๊ฒ 90%์์ ํ
์คํธ ์ผ์ด์ค ํต๊ณผ๊ฐ ์๋์ด์ ์ซ์ํ์ ์ฒ๋ฆฌํ๋ ๊ฒ์ผ๋ก ๋ฐ๊พธ์ด์ ํ์๋ค.
ํ์ด์ฌ์ผ๋ก ํ๋ ๋ฌธ์ ๋ค์ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๋ค์ ํ๋ค๋ณด๋๊น ๋ฏ์ค๊ณ ์ด์ํ๊ธฐ๋ ํ์ง๋ง
์ ์ฐจ ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ํธํด์ง๋ ๋๋์ด๋ผ ์ฌ๋ฏธ์๊ณ ๊ธฐ๋ถ์ด ์ข๋ค. :)
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 8958 (0) | 2022.05.14 |
---|---|
[JS] 4344 (0) | 2022.05.14 |
[JS] 10951 (0) | 2022.05.12 |
[JS] 10871 (0) | 2022.05.11 |
[JS] 2438 (0) | 2022.05.11 |