didkoslawow

Untitled

Jan 15th, 2023
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. function pyramid(baseSize, baseHigth) {
  2. let totalStones = 0;
  3. let totalMarbels = 0;
  4. let totalLapisLazuli = 0;
  5. let totalGoldBlocks = 0;
  6. let totalSteps = 0;
  7.  
  8. for (let i = baseSize; i > 0; i -= 2) {
  9. totalSteps++;
  10. let outerLayer = (i * 4 - 4) * baseHigth;
  11. let innerLayer = (i - 2) * (i - 2) * baseHigth;
  12.  
  13. if (i <= 2) {
  14. totalGoldBlocks = i * i * baseHigth;
  15. break;
  16. } else if (totalSteps % 5 == 0) {
  17. totalLapisLazuli += outerLayer;
  18. totalStones += innerLayer;
  19. } else {
  20. totalMarbels += outerLayer;
  21. totalStones += innerLayer;
  22. }
  23. }
  24.  
  25. let pyramidHigth = totalSteps * baseHigth;
  26.  
  27. console.log(`Stone required: ${Math.ceil(totalStones)}`);
  28. console.log(`Marble required: ${Math.ceil(totalMarbels)}`);
  29. console.log(`Lapis Lazuli required: ${Math.ceil(totalLapisLazuli)}`);
  30. console.log(`Gold required: ${Math.ceil(totalGoldBlocks)}`);
  31. console.log(`Final pyramid height: ${Math.floor(pyramidHigth)}`);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment