diff --git a/06/code.js b/06/code.js new file mode 100644 index 0000000..5d01159 --- /dev/null +++ b/06/code.js @@ -0,0 +1,20 @@ +const fs = require('fs'); +const inputArray = fs.readFileSync('input.txt').toString().split(",").map(Number); + +function countFish(days) { + const fishPerDay = new Array(9).fill(0); // Array of number of fish at each day remaining + inputArray.forEach(f => (fishPerDay[f]++)); // Populate the array based on the input + + for (let d = 0; d < days; d++){ + const fish = fishPerDay.shift(); // The number of fish at zero + (fishPerDay.push(fish)) && (fishPerDay[6] += fish); // Put that many fish at eight and add this number to six + } + + return fishPerDay.reduce((a, b) => a + b, 0); // add up all the fish +} + +// Part One +console.log(countFish(80)); + +// Part Two +console.log(countFish(256)); \ No newline at end of file diff --git a/06/input.txt b/06/input.txt new file mode 100644 index 0000000..c83b26a --- /dev/null +++ b/06/input.txt @@ -0,0 +1 @@ +4,5,3,2,3,3,2,4,2,1,2,4,5,2,2,2,4,1,1,1,5,1,1,2,5,2,1,1,4,4,5,5,1,2,1,1,5,3,5,2,4,3,2,4,5,3,2,1,4,1,3,1,2,4,1,1,4,1,4,2,5,1,4,3,5,2,4,5,4,2,2,5,1,1,2,4,1,4,4,1,1,3,1,2,3,2,5,5,1,1,5,2,4,2,2,4,1,1,1,4,2,2,3,1,2,4,5,4,5,4,2,3,1,4,1,3,1,2,3,3,2,4,3,3,3,1,4,2,3,4,2,1,5,4,2,4,4,3,2,1,5,3,1,4,1,1,5,4,2,4,2,2,4,4,4,1,4,2,4,1,1,3,5,1,5,5,1,3,2,2,3,5,3,1,1,4,4,1,3,3,3,5,1,1,2,5,5,5,2,4,1,5,1,2,1,1,1,4,3,1,5,2,3,1,3,1,4,1,3,5,4,5,1,3,4,2,1,5,1,3,4,5,5,2,1,2,1,1,1,4,3,1,4,2,3,1,3,5,1,4,5,3,1,3,3,2,2,1,5,5,4,3,2,1,5,1,3,1,3,5,1,1,2,1,1,1,5,2,1,1,3,2,1,5,5,5,1,1,5,1,4,1,5,4,2,4,5,2,4,3,2,5,4,1,1,2,4,3,2,1 \ No newline at end of file