[백준2292_자바스크립트(javascript)] - 벌집

경이·2024년 8월 1일

𝑩𝑶𝑱 (𝒋𝒔)

목록 보기
102/325

🔴 문제

벌집


🟡 Sol

const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : 'Wiki\\input.txt';
const inputs = fs.readFileSync(path).toString();
const n = Number(inputs);

let room = 1;
let line = 1;

while (n > room) {
  room += line * 6;
  line += 1;
}

console.log(line);

🟢 풀이

⏰ 소요한 시간 : 30분

ㅠ 몰라서 풀이를 찾아봤다.
분명 3년전에 풀었던 기억이 있는데 답을 찾아봐도 모르겠다.

풀이를 보자면 1번방부터 n번방이 될 때까지 돌아주는데
line이 1씩 증가할 때 마다 room은 6씩 커진다.

뭔가 쉬운듯 어렵다....


🔵 Ref

https://develop247.tistory.com/345

profile
록타르오가르

1개의 댓글

comment-user-thumbnail
2024년 8월 3일

쉬운듯 어려웠다는 표현은 다소 모호한 것 같습니다.
게시글 포스팅은 장난이 아니라는 점.
유의해주시길 바랍니다

답글 달기