Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(base, increment) {
- let totalStone = 0;
- let totalMarble = 0;
- let totalLapis = 0;
- let totalGold = 0;
- let steps = Math.ceil(base / 2);
- let height = Math.floor(steps * increment);
- for (let step = 1; step <= steps; step++) {
- if (step === steps) {
- totalGold += base * base*increment;
- } else if (step % 5 === 0) {
- totalStone += (base - 2) * (base - 2)*increment;
- totalLapis += base * base*increment - (base - 2) * (base - 2) * increment;
- base -= 2;
- } else if (step % 5 !== 0) {
- totalStone += (base - 2) * (base - 2) * increment;
- totalMarble += base * base *increment - (base - 2) * (base - 2)*increment;
- base -= 2;
- }
- }
- console.log(`Stone required: ${Math.ceil(totalStone)}`);
- console.log(`Marble required: ${Math.ceil(totalMarble)}`);
- console.log(`Lapis Lazuli required: ${Math.ceil(totalLapis)}`);
- console.log(`Gold required: ${Math.ceil(totalGold)}`);
- console.log(`Final pyramid height: ${height}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment