Untitled
unknown
javascript
4 years ago
559 B
13
Indexable
const simulateBig = (state, maxIteration, currentIteration = 0) => {
if (maxIteration === currentIteration) {
const res = state.reduce((acc, val) => acc + val, 0);
console.log(res);
return;
}
const newFishesNo = state[0];
const newState = state.slice(1);
newState[6] += newFishesNo;
newState[8] = newFishesNo;
simulateBig(newState, maxIteration, ++currentIteration);
}
//b
const bigMap = allNumbers.reduce((acc, val) => {
acc[val] += 1;
return acc;
}, Array(9).fill(0));
simulateBig(bigMap, 256);Editor is loading...