Skip to content

Instantly share code, notes, and snippets.

@dannyrb
Created December 7, 2021 17:19
Show Gist options
  • Save dannyrb/a5002370c56e5f16dd9ff0d864c49f33 to your computer and use it in GitHub Desktop.
Save dannyrb/a5002370c56e5f16dd9ff0d864c49f33 to your computer and use it in GitHub Desktop.
Advent of Code Fishies
const fs = require('fs');
const path = require('path');
const problemPart = 1;
const fileName = `input-${problemPart}.txt`;
const input = fs.readFileSync(path.resolve(__dirname, fileName), 'utf8')
const inputArray = input.split(',').map(x => Number(x));
function timeTravel(fishies, timeTravelDays) {
let fishBirthDayCounts = {
0: fishies.filter(x => x === 0).length,
1: fishies.filter(x => x === 1).length,
2: fishies.filter(x => x === 2).length,
3: fishies.filter(x => x === 3).length,
4: fishies.filter(x => x === 4).length,
5: fishies.filter(x => x === 5).length,
6: fishies.filter(x => x === 6).length,
7: fishies.filter(x => x === 7).length,
8: fishies.filter(x => x === 8).length,
}
for (let currentDay = 0; currentDay < timeTravelDays; currentDay++) {
fishBirthDayCounts = {
0: fishBirthDayCounts['1'],
1: fishBirthDayCounts['2'],
2: fishBirthDayCounts['3'],
3: fishBirthDayCounts['4'],
4: fishBirthDayCounts['5'],
5: fishBirthDayCounts['6'],
6: fishBirthDayCounts['7'] + fishBirthDayCounts['0'],
7: fishBirthDayCounts['8'],
8: fishBirthDayCounts['0'],
}
}
let total = 0;
Object.keys(fishBirthDayCounts).forEach(x => {
total += fishBirthDayCounts[x]
});
console.log(fishBirthDayCounts)
console.log(total)
}
console.log('~~ 80')
timeTravel(inputArray, 80)
console.log('~~ 256')
timeTravel(inputArray, 256)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment