Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pyramid(baseSize, baseHigth) {
- let totalStones = 0;
- let totalMarbels = 0;
- let totalLapisLazuli = 0;
- let totalGoldBlocks = 0;
- let totalSteps = 0;
- let pyramidHigth = 0;
- let currentBase = 0;
- for (let i = baseSize; i > 1; i -= 2) {
- let outerLayer = (i * 4 - 4) * baseHigth;
- let innerLayer = (i - 2) * (i - 2) * baseHigth;
- if (i - 2 == 0) {
- break;
- }
- totalSteps++;
- if (totalSteps % 5 == 0) {
- totalLapisLazuli += outerLayer;
- totalStones += innerLayer;
- } else {
- totalMarbels += outerLayer;
- totalStones += innerLayer;
- }
- currentBase = i - 2;
- }
- totalSteps++;
- if (currentBase == 0) {
- totalGoldBlocks = 1;
- } else {
- totalGoldBlocks = currentBase * currentBase * baseHigth;
- }
- pyramidHigth = totalSteps * baseHigth;
- console.log(`Stone required: ${Math.ceil(totalStones)}`);
- console.log(`Marble required: ${Math.ceil(totalMarbels)}`);
- console.log(`Lapis Lazuli required: ${Math.ceil(totalLapisLazuli)}`);
- console.log(`Gold required: ${Math.ceil(totalGoldBlocks)}`);
- console.log(`Final pyramid height: ${Math.floor(pyramidHigth)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment