georgiev955

Pyramid

May 13th, 2023
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(base, increment) {
  2.     let totalStone = 0;
  3.     let totalMarble = 0;
  4.     let totalLapis = 0;
  5.     let totalGold = 0;
  6.     let steps = Math.ceil(base / 2);
  7.     let height = Math.floor(steps * increment);
  8.  
  9.     for (let step = 1; step <= steps; step++) {
  10.         if (step === steps) {
  11.             totalGold += base * base*increment;
  12.         } else if (step % 5 === 0) {
  13.             totalStone += (base - 2) * (base - 2)*increment;
  14.             totalLapis += base * base*increment - (base - 2) * (base - 2) * increment;
  15.             base -= 2;
  16.         } else if (step % 5 !== 0) {
  17.             totalStone += (base - 2) * (base - 2) * increment;
  18.             totalMarble += base * base *increment - (base - 2) * (base - 2)*increment;
  19.             base -= 2;
  20.         }
  21.     }
  22.  
  23.     console.log(`Stone required: ${Math.ceil(totalStone)}`);
  24.     console.log(`Marble required: ${Math.ceil(totalMarble)}`);
  25.     console.log(`Lapis Lazuli required: ${Math.ceil(totalLapis)}`);
  26.     console.log(`Gold required: ${Math.ceil(totalGold)}`);
  27.     console.log(`Final pyramid height: ${height}`);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment