vikkktor

Excercises-Basic Syntax_10.thePiramydofKingDjoser

Sep 26th, 2021 (edited)
913
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(base, inc) {
  2.     let stoneBricks = 0
  3.     let marbleBricks = 0
  4.     let lazuriBricks = 0
  5.     let goldBricks = 0
  6.     let height = 0
  7.  
  8.     let currentLayer = 0
  9.  
  10.     while (base >= 1) {
  11.         currentLayer += 1
  12.         if (currentLayer % 5 == 0) {
  13.             lazuriBricks += ((base * 4) - 4) * inc
  14.         } else {
  15.             marbleBricks += ((base * 4) - 4) * inc
  16.         }
  17.  
  18.  
  19.         if (base === 1 || base === 2) {
  20.             // goldBricks += base * base * inc
  21.         } else {
  22.             stoneBricks += ((base - 2) * (base - 2)) * inc
  23.         }
  24.  
  25.         base -= 2
  26.     }
  27.  
  28.  
  29.     height = currentLayer * inc
  30.     console.log(`Stone required: ${Math.ceil(stoneBricks)}`)
  31.     console.log(`Marble required: ${Math.ceil(marbleBricks)}`)
  32.     console.log(`Lapis Lazuli required: ${Math.ceil(lazuriBricks)}`)
  33.     console.log(`Gold required: ${Math.ceil(goldBricks)}`)
  34.     console.log(`Final pyramid height: ${Math.floor(height)}`)
  35. }
  36.  
  37. solve(23, 0.5);
RAW Paste Data