Prevent recalculating common multiple
This commit is contained in:
parent
54caefb22e
commit
02fb31d09d
@ -122,13 +122,14 @@ console.log(
|
|||||||
`Level of monkey business after 20 rounds: ${monkeyBusinessLevel}`
|
`Level of monkey business after 20 rounds: ${monkeyBusinessLevel}`
|
||||||
);
|
);
|
||||||
|
|
||||||
monkeys = getMonkeys(item => {
|
let commonMultiple;
|
||||||
const commonMultiple = [...monkeys.values()]
|
monkeys = getMonkeys(
|
||||||
|
// Reduce item by commonMultiple whenever it exceeds that value
|
||||||
|
item => item.worryLevel = item.worryLevel % commonMultiple
|
||||||
|
);
|
||||||
|
commonMultiple = [...monkeys.values()]
|
||||||
.map(monkey => monkey.test.divisibleBy)
|
.map(monkey => monkey.test.divisibleBy)
|
||||||
.reduce((total, divisibleBy) => total * divisibleBy);
|
.reduce((total, divisibleBy) => total * divisibleBy);
|
||||||
// Reduce item by commonMultiple whenever it exceeds that value
|
|
||||||
return item.worryLevel = item.worryLevel % commonMultiple;
|
|
||||||
});
|
|
||||||
simulateRounds(monkeys, 10000);
|
simulateRounds(monkeys, 10000);
|
||||||
monkeyBusinessLevel = calculateMonkeyBusinessLevel(monkeys);
|
monkeyBusinessLevel = calculateMonkeyBusinessLevel(monkeys);
|
||||||
console.log(
|
console.log(
|
||||||
|
Loading…
Reference in New Issue
Block a user