Skip to content

Instantly share code, notes, and snippets.

@haithamsha
Created July 22, 2019 02:00
Show Gist options
  • Save haithamsha/3be9229ce54b541d6f341f9c5bad8a6e to your computer and use it in GitHub Desktop.
Save haithamsha/3be9229ce54b541d6f341f9c5bad8a6e to your computer and use it in GitHub Desktop.
Mairo problem solution with javascript
makePyramid(2);
function makePyramid(n) {
n = n *2+2;
r = parseInt(n/2) + 1;
for(var i=2;i<n;i+=2) {
// inject spaces before every hash line
// number of spaces r = n/2 + 1
var z = (n-i)/2+1;
process.stdout.write(returnSpaces(z));
for(var j=i;j>0;j--) {
process.stdout.write("#");
if(j == (i/2)+1) {
process.stdout.write(" ");
}
}
process.stdout.write("\n");
}
}
function returnSpaces(h) {
var result = "";
for(var i =0;i<h;i++) {
result = result + " ";
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment