mirror of
https://github.com/peter-tanner/advent-of-code-2023.git
synced 2024-11-30 14:00:16 +08:00
28 lines
547 B
TypeScript
28 lines
547 B
TypeScript
import * as fs from "fs";
|
|
|
|
const input = fs.readFileSync("input", "utf8");
|
|
|
|
const cards = input.split("\n").map((card) =>
|
|
card
|
|
.split(": ")[1]
|
|
.split(" | ")
|
|
.map((part) =>
|
|
part
|
|
.split(" ")
|
|
.filter((num) => num !== "")
|
|
.map((num) => parseInt(num))
|
|
)
|
|
);
|
|
|
|
console.log(
|
|
cards
|
|
.map((card) =>
|
|
card[1].reduce(
|
|
(score, your_number) =>
|
|
card[0].includes(your_number) ? (score === 0 ? 1 : score * 2) : score,
|
|
0
|
|
)
|
|
)
|
|
.reduce((sum, score) => sum + score, 0)
|
|
);
|