Created
December 6, 2021 05:11
-
-
Save bluepichu/74a017f966abb742fc272ef261426d5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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