-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path06.js
45 lines (39 loc) · 763 Bytes
/
06.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
44
45
'use strict';
/**
* @param {[*]} arr
*/
function rotate_array(arr) {
const first = arr.shift();
arr.push(first);
}
/**
* @param {[number]} data
* @param {number} days
* @returns
*/
function simulateFish(data, days) {
const fishLife = new Array(9).fill(0);
data.forEach(fish => {
fishLife[fish]++;
});
while (days) {
days--;
rotate_array(fishLife);
fishLife[6] += fishLife[8];
}
return fishLife.reduce((p, v) => p + v, 0);
}
/**
* @param {string} d
*/
export const part1 = async d => {
const data = d.split(',').map(e => parseInt(e, 10));
return simulateFish(data, 80);
};
/**
* @param {string} d
*/
export const part2 = async d => {
const data = d.split(',').map(e => parseInt(e, 10));
return simulateFish(data, 256);
};