Created
July 22, 2019 02:00
-
-
Save haithamsha/3be9229ce54b541d6f341f9c5bad8a6e to your computer and use it in GitHub Desktop.
Mairo problem solution with javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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