Untitled

mail@pastecode.io avatar
unknown
javascript
3 years ago
559 B
3
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);