diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-12-01 14:44:40 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-12-01 14:44:40 +0300 |
commit | 2b46414178af362b8134bbbf2459370bd67c6aa1 (patch) | |
tree | 06d12b66f7b71de8898bcf1802b052566c280d9d /day-1/script.ts | |
parent | f32a28c2ca7bed33e648d34f1b15ab6e0ed00a53 (diff) | |
download | aoc-2023-2b46414178af362b8134bbbf2459370bd67c6aa1.tar.gz |
feat(day-1): add first part solution
Diffstat (limited to 'day-1/script.ts')
-rw-r--r-- | day-1/script.ts | 15 |
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 }); |