diff --git a/2021/6.js b/2021/6.js index 040aa70..36a634f 100644 --- a/2021/6.js +++ b/2021/6.js @@ -1,14 +1,11 @@ -function iterate(counts) { - return [counts[1], counts[2], counts[3], counts[4], counts[5], counts[6], counts[7] + counts[0], counts[8], counts[0]] -} - function day6(input, part2) { input = input.split(",").num() let counts = Array(9).fill().map((_, i) => input.count(i)) for (let i = 0; i < (part2 ? 256 : 80); i++) { - counts = iterate(counts) + counts = counts.rotate(1) + counts[6] += counts[8] } return counts.sum()