mirror of
https://github.com/Baipyrus/AoC-23.git
synced 2024-11-14 17:53:49 +00:00
20 lines
470 B
JavaScript
20 lines
470 B
JavaScript
|
import { readFileSync } from "fs";
|
||
|
const t0 = performance.now();
|
||
|
|
||
|
const lines = readFileSync("input.txt")
|
||
|
.toString()
|
||
|
.split("\n")
|
||
|
.filter((e) => e.length > 0);
|
||
|
const numbers = lines.map((a) =>
|
||
|
a
|
||
|
.split("")
|
||
|
.filter((b) => parseInt(b))
|
||
|
.join("")
|
||
|
);
|
||
|
const combinations = numbers.map((e) => parseInt(e[0] + e[e.length - 1]));
|
||
|
const sum = combinations.reduce((a, i) => a + i);
|
||
|
console.log(sum);
|
||
|
|
||
|
const t1 = performance.now();
|
||
|
console.log(`Runtime: ${t1 - t0}ms`);
|