diff --git a/2021/6.js b/2021/6.js new file mode 100644 index 0000000..040aa70 --- /dev/null +++ b/2021/6.js @@ -0,0 +1,15 @@ +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) + } + + return counts.sum() +}