Skip to content

Instantly share code, notes, and snippets.

@ernestlv
Created November 16, 2015 21:58
Show Gist options
  • Save ernestlv/57308c5cb194b1c11e9a to your computer and use it in GitHub Desktop.
Save ernestlv/57308c5cb194b1c11e9a to your computer and use it in GitHub Desktop.
Stair-case Problem
process.stdin.resume();
process.stdin.setEncoding("ascii");
var input = "";
process.stdin.on("data", function (chunk) {
input += chunk;
});
process.stdin.on("end", function () {
// now we can read/parse input
var n = parseInt(input, 10);
var str = [];
for(var i=0; i<n; i++){
var col = n-i-1;
for(var j=0; j<n; j++){
if (j>=col){
str.push('#');
}else{
str.push(' ');
}
}
str.push('\n');
}
process.stdout.write(str.join(''));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment