Skip to content

Instantly share code, notes, and snippets.

@asonge
Created December 6, 2021 20:46
Show Gist options
  • Save asonge/6d822b30d08da1d495a2372b7735e121 to your computer and use it in GitHub Desktop.
Save asonge/6d822b30d08da1d495a2372b7735e121 to your computer and use it in GitHub Desktop.
function part1(input, days) {
let gens = [0,0,0,0,0,0,0,0,0]
input.split(',').forEach((x) => gens[x]++)
let zeroes = 0;
for(let d=0;d<days;d++) {
[zeroes, ...gens] = gens;
gens.push(zeroes)
gens[6] += zeroes
}
console.log(gens.reduce((a,b) => a+b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment