Advertisement
Pijomir

The Pyramid of King Djoser

Aug 4th, 2022 (edited)
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function thePyramidOfKingDjoser(base, increment) {
  2.     let step = 0;
  3.     let stone = 0;
  4.     let marble = 0;
  5.     let lapisLazuli = 0;
  6.     let gold = 0;
  7.  
  8.     while (base > 0) {
  9.         step++;
  10.         if (base <= 2) {
  11.             gold = Math.pow(base, 2) * increment;
  12.         } else {
  13.             stone += Math.pow(base - 2, 2) * increment;
  14.             if (step % 5 === 0) {
  15.                 lapisLazuli += (Math.pow(base, 2) - Math.pow(base - 2, 2)) * increment;
  16.             } else {
  17.                 marble += (Math.pow(base, 2) - Math.pow(base - 2, 2)) * increment;
  18.             }
  19.         }
  20.         base -= 2;
  21.     }
  22.     let pyramidHeight = Math.floor(step * increment);
  23.  
  24.     console.log(`Stone required: ${Math.ceil(stone)}`);
  25.     console.log(`Marble required: ${Math.ceil(marble)}`);
  26.     console.log(`Lapis Lazuli required: ${Math.ceil(lapisLazuli)}`);
  27.     console.log(`Gold required: ${Math.ceil(gold)}`);
  28.     console.log(`Final pyramid height: ${pyramidHeight}`);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement