# Pyramid of King Djoser

May 20th, 2022 (edited)
840
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. // 80 of 100 points
2. function solve(base, step) {
3.     let increment = step
4.     let stone = 0
5.     let marble = 0
6.     let lapisLazuli = 0
7.     let gold = 0
8.
9.     let currentBase = base
10.     let outerLayer = 0
11.     let currentStone = 0
12.     let currentMarble = 0
13.     let currentLapis = 0
14.     let currentGold = 0
15.
16.     let nextCurrentBase = base
17.     let row = 0
18.
19.     while (currentBase > 2) {
20.         row++
21.         nextCurrentBase -= 2
22.         outerLayer = 2 * currentBase + 2 * (currentBase - 2)
23.
24.         if (nextCurrentBase < step) { // last row
25.             break
26.         }
27.
28.         if (row % 5 === 0) { // every 5th row
29.             // console.log("lapis")
30.             currentLapis = outerLayer
31.         } else {
32.             // console.log("marble")
33.             currentMarble = outerLayer
34.         }
35.         currentStone = currentBase * currentBase - outerLayer
36.         increment--
37.         currentBase = nextCurrentBase
38.
39.         stone += (currentStone * step)
40.         marble += (currentMarble * step)
41.         lapisLazuli += (currentLapis * step)
42.
43.         currentStone = 0
44.         currentMarble = 0
45.         currentLapis = 0
46.     }
47.     currentGold = currentBase * currentBase
48.     gold += currentGold * step
49.
50.     row++
51.
52.     console.log(`Stone required: \${Math.round(stone)}`)
53.     console.log(`Marble required: \${Math.round(marble)}`)
54.     console.log(`Lapis Lazuli required: \${Math.round(lapisLazuli)}`)
55.     console.log(`Gold required: \${Math.round(gold)}`)
56.     console.log(`Final pyramid height: \${Math.floor(row * step)}`)
57. }