diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-11-30 22:46:45 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-11-30 22:46:45 -0700 |
commit | 3d57434c04a669610d5f15bd2a7713e6928cdef7 (patch) | |
tree | a0f1f04a335bbc808369d6492f4fee2ff06a0bdb /aoc_2023/day0/main_1.js | |
parent | 59966ade163a39fc03f07a9d905e0bd87a98d60c (diff) | |
download | aoc-3d57434c04a669610d5f15bd2a7713e6928cdef7.tar.gz aoc-3d57434c04a669610d5f15bd2a7713e6928cdef7.zip |
add aoc2023
Diffstat (limited to 'aoc_2023/day0/main_1.js')
-rw-r--r-- | aoc_2023/day0/main_1.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/aoc_2023/day0/main_1.js b/aoc_2023/day0/main_1.js new file mode 100644 index 0000000..aa00ffe --- /dev/null +++ b/aoc_2023/day0/main_1.js @@ -0,0 +1,18 @@ +const fs = require("node:fs"); + +const data = fs.readFileSync("input.txt", "utf8"); + +const res = data + .split("\n") + .filter((line) => line && line != "") + .map((line) => line.replaceAll(/[^0-9]*/g, "")) + .reduce((acc, line) => { + const nums = line.split(""); + + const first = parseInt(nums.at(0)); + const last = parseInt(nums.at(-1)); + + return acc + (first * 10 + last); + }, 0); + +console.log(res); |