Skip to content

Instantly share code, notes, and snippets.

@bluepichu
Created December 6, 2021 05:11
Show Gist options
  • Save bluepichu/74a017f966abb742fc272ef261426d5f to your computer and use it in GitHub Desktop.
Save bluepichu/74a017f966abb742fc272ef261426d5f to your computer and use it in GitHub Desktop.
import { List } from "immutable";
import { Advent, int } from "advent";
const { compute, computeCheck } = await Advent({ day: 6 });
compute(async (input) => {
let count = Array.from(new Array(9), () => 0);
let init = input.tokens(/,/).map(int);
for (let v of init) {
count[v]++;
}
console.log(count);
for (let i = 0; i < 256; i++) {
let next = Array.from(new Array(9), () => 0);
for (let j = 0; j < count.length; j++) {
if (j === 0) {
next[6] += count[j];
next[8] += count[j];
} else {
next[j - 1] += count[j];
}
}
count = next;
console.log(count);
}
return count.reduce((a, b) => a + b, 0);
}, 2);
// computeCheck(async function* (input) {
// yield 0;
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment