Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function thePyramidOfKingDjoser (basis, increment) {
- let step = 0;
- let stone = 0;
- let marble = 0;
- let lapis = 0;
- let gold = 0;
- for (let i = basis; i > 0; i -= 2) {
- let size = i * i;
- step++;
- if (i < 3) {
- gold = size * increment;
- } else {
- stone += (i - 2) * (i - 2) * increment;
- let decorate = (i * 4 - 4) * increment;
- if (step % 5 !== 0) {
- marble += decorate;
- } else {
- lapis += decorate;
- }
- }
- }
- console.log(`Stone required: ${Math.ceil(stone)}`);
- console.log(`Marble required: ${Math.ceil(marble)}`);
- console.log(`Lapis Lazuli required: ${Math.ceil(lapis)}`);
- console.log(`Gold required: ${Math.ceil(gold)}`);
- console.log(`Final pyramid height: ${Math.floor(step * increment)}`);
- }
- РЕШЕНИЕ С КОЛЕКЦИЯ И ТЕРНАРЕН ОПЕРАТОР И FOR IN:
- function thePyramidOfKingDjoser(basis, increment) {
- let info = { 'stone': 0, 'marble': 0, 'lapis': 0, 'gold': 0, 'step': 0 };
- for (let i = basis; i > 0; i -= 2) {
- info['step']++;
- info[i < 3 ? 'gold' : 'stone'] += (i < 3 ? i : (i - 2)) ** 2 * increment;
- i >= 3 ? info[info['step'] % 5 !== 0 ? 'marble' : 'lapis'] += (i * 4 - 4) * increment : info;
- }
- for (i in info) {
- console.log(i !== 'step' ? `${i[0].toUpperCase() + i.slice(1)}${i === 'lapis' ? ' Lazuli' : ''} required: ${Math.ceil(info[i])}` :
- `Final pyramid height: ${Math.floor(info['step'] * increment)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement