-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.js
43 lines (33 loc) · 1.15 KB
/
1.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
32
33
34
35
36
37
38
39
40
41
42
43
import input from "./input.js";
import Timeline from "./1/Timeline.js";
import Lanternfish from "./1/Lanternfish.js";
class LanternFishesGroupSimulator {
timeline = null
lanternFishesGroup = []
constructor (simulationDuration, fishesLifeExpectancies) {
this.lanternFishesGroup = fishesLifeExpectancies.map(fishLifeExpectancy => new Lanternfish(fishLifeExpectancy))
this.timeline = new Timeline(simulationDuration)
}
getResult = () => {
while (!this.timeline.isFinished()) {
this.lanternFishesGroup.forEach(fish => {
if (!fish.shouldDivideAndRevive()) {
fish.decreaseLife()
return
}
fish.revive()
this.lanternFishesGroup.push(new Lanternfish())
})
this.timeline.advance()
}
return this.lanternFishesGroup.length
}
}
const output = new LanternFishesGroupSimulator(80, input).getResult()
console.log({
title: 'Lanternfish [6.1]',
url: 'https://adventofcode.com/2021/day/6',
inputPreview: input.slice(0, 5),
inputLength: input.length,
output,
})