Skip to main content

[BAEKJOON Online Judge + Node.js] 2292: Honeycomb

 


I did't use while loop that much so didn't come up what to do. While loop create a loop that execute a specific statement. So, the main point of this problem is "prevNum + max * 6"

input = 13, output = 3


https://www.acmicpc.net/problem/2292


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while


const input = require("fs").readFileSync("/dev/stdin").toString();

let count = 1;
let max = 1;

// set the range

while (max < input) {
max += count * 6;
count++;
}

console.log(count);

// prevNum + count * 6
// 1 so +6 every loop!
// 2 - 7, 5
// 8 - 19, 11
// 20 - 37, 17
// 38 - 61, 23

Comments

Popular posts from this blog

29/06/2021 TIL

1. PS(BOJ/Programmers) update programmers questions on github  2. Project (DividendDB & OXINION) with JS/React Fundamental of JS course  3. CS for Interview summary interview questions