didkoslawow

The Pyramid of King Djoser

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