3vo

Pyramid

3vo
May 14th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Pyramid(base, increment) {
  2.   let totalstone = 0;
  3.   let totalmarble = 0;
  4.   let totallapis = 0;
  5.   let totalgold = 0;
  6.   let row = 0;
  7.   let currentbase = base;
  8.  
  9.   while (currentbase > 2) {
  10.     let marbel = currentbase * 4 - 4;
  11.     let stone = currentbase * currentbase - marbel;
  12.     totalstone += stone;
  13.  
  14.     row++;
  15.     if (row % 5 === 0) {
  16.       totallapis += marbel;
  17.     } else {
  18.       totalmarble += marbel;
  19.     }
  20.     currentbase -= 2;
  21.   }
  22.   row++;
  23.   let gold = currentbase * currentbase;
  24.  
  25.   stone = Math.ceil(totalstone * increment);
  26.   marble = Math.ceil(totalmarble * increment);
  27.   lapis = Math.ceil(totallapis * increment);
  28.   totalgold = Math.ceil(gold * increment);
  29.   totalHeight = Math.floor(row * increment);
  30.  
  31.   console.log(`Stone required: ${stone}`);
  32.   console.log(`Marble required: ${marble}`);
  33.   console.log(`Lapis Lazuli required: ${lapis}`);
  34.   console.log(`Gold required: ${totalgold}`);
  35.   console.log(`Final pyramid height: ${totalHeight}`);
  36. }
  37. Pyramid(11, 0.75);
Add Comment
Please, Sign In to add comment