Advertisement
dabidabidesh

Untitled

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