summaryrefslogtreecommitdiff
path: root/day-1/script.ts
diff options
context:
space:
mode:
Diffstat (limited to 'day-1/script.ts')
-rw-r--r--day-1/script.ts15
1 files changed, 15 insertions, 0 deletions
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 });