Liliana797979

piramid of djoser - fundamentals

May 28th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function pyramidOfKingDjoser(base , step){
  3.     let totalStone = 0;
  4.     let totalMarble = 0;
  5.     let totalLapis = 0;
  6.  
  7.     let row = 0;
  8.     row ++;
  9.     let currentSize = base;
  10.  
  11.     while(currentSize > 2){
  12.         let marble = (currentSize * 4) - 4;
  13.         let stone = (currentSize * currentSize) - marble;
  14.  
  15.         if(row % 5 === 0){
  16.             totalLapis += marble;
  17.         } else {
  18.             totalMarble += marble;
  19.         }
  20.  
  21.         totalStone += stone;
  22.         currentSize -= 2;
  23.         row++;
  24.     }
  25.    
  26.     let totalGold = 0;
  27.  
  28.     if(currentSize <= 1){
  29.         totalGold = 1;
  30.     } else {
  31.         totalGold = currentSize * 2;
  32.     }
  33.    
  34.     totalStone = Math.ceil(totalStone * step);
  35.     totalMarble = Math.ceil(totalMarble * step);
  36.     totalLapis = Math.ceil(totalLapis * step);
  37.     totalGold = Math.ceil(totalGold * step);
  38.  
  39.     let height = Math.floor(row * step);
  40.  
  41.     let print = `Stone required: ${totalStone}\n` +
  42.     `Marble required: ${totalMarble}\n` +
  43.     `Lapis Lazuli required: ${totalLapis}\n` +
  44.     `Gold required: ${totalGold}\n` +
  45.     `Final pyramid height: ${height}`;
  46.  
  47.     console.log(print);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment