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}`
|
||||
);
|
||||
|
||||
monkeys = getMonkeys(item => {
|
||||
const commonMultiple = [...monkeys.values()]
|
||||
let commonMultiple;
|
||||
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)
|
||||
.reduce((total, divisibleBy) => total * divisibleBy);
|
||||
// Reduce item by commonMultiple whenever it exceeds that value
|
||||
return item.worryLevel = item.worryLevel % commonMultiple;
|
||||
});
|
||||
simulateRounds(monkeys, 10000);
|
||||
monkeyBusinessLevel = calculateMonkeyBusinessLevel(monkeys);
|
||||
console.log(
|
||||
|
Loading…
Reference in New Issue
Block a user