From 2b46414178af362b8134bbbf2459370bd67c6aa1 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 1 Dec 2023 14:44:40 +0300 Subject: feat(day-1): add first part solution --- day-1/script.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 day-1/script.ts (limited to 'day-1/script.ts') diff --git a/day-1/script.ts b/day-1/script.ts new file mode 100644 index 0000000..9e444ba --- /dev/null +++ b/day-1/script.ts @@ -0,0 +1,15 @@ +import fs from "fs"; + +const input = fs.readFileSync("./input.txt").toString(); + +const result = input + .split("\n") + .slice(0, -1) + .map((line) => line.match(/\d/g)) + .reduce((acc, value) => { + if (!value) + throw new Error(`The string must contain at least one digit ${value}`); + return acc + Number(value[0] + value[value.length - 1]); + }, 0); + +console.log({ result }); -- cgit v1.2.3