From 138b4e2944f9828b4566108a41fdac2d59f3319c Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Fri, 15 Dec 2023 20:38:40 +0100 Subject: [PATCH] init d15p2 --- Day15/Part2.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Day15/Part2.js diff --git a/Day15/Part2.js b/Day15/Part2.js new file mode 100644 index 0000000..f02ceea --- /dev/null +++ b/Day15/Part2.js @@ -0,0 +1,12 @@ +import { readFileSync } from "fs"; +const t0 = performance.now(); + +const input = readFileSync("input.txt").toString().split("\n")[0].split(","); +const hashes = input.map((e) => + e.split("").reduce((a, i) => ((a + i.charCodeAt(0)) * 17) % 256, 0) +); +const sum = hashes.reduce((a, i) => a + i); +console.log(sum); + +const t1 = performance.now(); +console.log(`Runtime: ${t1 - t0}ms`);