-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.js
31 lines (23 loc) · 1.04 KB
/
2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import input from "./input.js";
class LanternFishesGroupSimulator {
maxLifeExpectancy = 9
summedUpLanternFishesGroup = []
constructor (simulationDuration, fishesLifeExpectancies) {
this.summedUpLanternFishesGroup = Array(this.maxLifeExpectancy).fill(0)
fishesLifeExpectancies.forEach(fishLifeExpectancy => this.summedUpLanternFishesGroup[fishLifeExpectancy]++)
for (let elapsedDays = 0; elapsedDays < simulationDuration; elapsedDays++) {
this.summedUpLanternFishesGroup[(7 + elapsedDays) % this.maxLifeExpectancy] += this.summedUpLanternFishesGroup[elapsedDays % this.maxLifeExpectancy]
}
}
getResult = () => {
return this.summedUpLanternFishesGroup.reduce((previousGroup, currentGroup) => previousGroup + currentGroup, 0)
}
}
const output = new LanternFishesGroupSimulator(256, input).getResult()
console.log({
title: 'Lanternfish [6.2]',
url: 'https://adventofcode.com/2021/day/6#part2',
inputPreview: input.slice(0, 5),
inputLength: input.length,
output,
})