https://programmers.co.kr/learn/courses/30/lessons/68645
function solution(n) {
const answer = new Array(n).fill().map((_, i) => new Array(i + 1)); //,,,,,,,,,
let count = 0;
let x = -1;
let y = 0;
while (n > 0) {
for (let i = 0; i < n; i++) answer[++x][y] = ++count; //first
for (let i = 0; i < n - 1; i++) answer[x][++y] = ++count; //second
for (let i = 0; i < n - 2; i++) answer[--x][--y] = ++count; //third
n -= 3;
}
return answer.flatMap(e => e);
}
// first: 1,2,,3,,,4,,,
// second: 1,2,,3,,,4,5,6,7
// third: 1,2,9,3,,8,4,5,6,7
// first: 1,2,9,3,10,8,4,5,6,7
// second: 1,2,9,3,10,8,4,5,6,7
// third: 1,2,9,3,10,8,4,5,6,7
어렵다 😵