Problem 32. pattern4.js(*** Revise***)
/*Question
Given a positive integer n, generate the following format.
suppose n is 3, then the format is
1
1 1 2
1 1 2 1 2 3
Algorithm:
1) Read the input number
2) Print the pattern
*/
let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split('\n');
function readLine() {
idx++;
return data[idx - 1].trim();
}
//..........................................................................................
let num = parseInt(readLine()); // 3
let tmp = '';
for (let i = 1; i <= num; i++) {
for (let j = 1; j <= i; j++) {
tmp = tmp + ' ' + j;
}
console.log(tmp);
console.log();
}
TERMINAL:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node pattern4.js <input.txt
1
1 1 2
1 1 2 1 2 3
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$
Comments
Post a Comment