Slackbot
12/06/2023, 5:04 PMMichael Cooper
12/06/2023, 5:05 PMfunction part2(input) {
const counts = Object.fromEntries(input.map(card => [card.id, 1]));
for (let card of input) {
let wins = new Set(card.winningNumbers);
let matchCount = card.playNumbers.filter(p => wins.has(p)).length;
for (let i = 0; i < matchCount; i++) {
let key = card.id + i + 1;
if (Object.hasOwn(counts, key)) {
counts[key] += counts[card.id];
}
}
}
return d3.sum(Object.values(counts));
}Michael Cooper
12/06/2023, 5:06 PMinput is pre-parsed from my puzzle input, and is an array of objects. I think the rest is pretty apparent, but happy to share more or explain more