Liliana797979

piramid of the king djoser - fundamentals

May 28th, 2021
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.      
  3. function thePyramidOfKingDjoser(input1, input2){
  4.     let widthLength = Number(input1);
  5.     let heigth = Number(input2);
  6.     let stoneBlocks = 0;
  7.     let marbleBlocks = 0;
  8.     let lapisBlocks = 0;
  9.     let goldBlocks = 0;
  10.     let stepCounter = 0;
  11.     let totalHeigth = 0;
  12.  
  13.     while(widthLength > 0){
  14.         totalHeigth += heigth;
  15.         stepCounter++;
  16.         let totalCurrentBlocks = widthLength * widthLength * heigth;
  17.         let innerBlocks = (widthLength - 2) * (widthLength - 2) * heigth;
  18.         let outsideBlocks = totalCurrentBlocks - innerBlocks;
  19.         if(widthLength < 3){
  20.             goldBlocks += totalCurrentBlocks;
  21.         } else{
  22.             stoneBlocks += innerBlocks;
  23.             if (stepCounter % 5 !== 0) {
  24.                 marbleBlocks += outsideBlocks;
  25.             } else {
  26.                 lapisBlocks += outsideBlocks;
  27.             }
  28.         }
  29.         widthLength -= 2;
  30.     }
  31.  
  32.     console.log(`Stone required: ${Math.ceil(stoneBlocks)}`);
  33.     console.log(`Marble required: ${Math.ceil(marbleBlocks)}`);
  34.     console.log(`Lapis Lazuli required: ${Math.ceil(lapisBlocks)}`);
  35.     console.log(`Gold required: ${Math.ceil(goldBlocks)}`);
  36.     console.log(`Final pyramid height: ${Math.floor(totalHeigth)}`);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment