From d6d3a06b85197e7fc20cb50862bf4b150af96273 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Fri, 15 Dec 2023 20:38:30 +0100 Subject: [PATCH] calc hashes, sum up --- Day15/Part1.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Day15/Part1.js b/Day15/Part1.js index 3a620a8..f02ceea 100644 --- a/Day15/Part1.js +++ b/Day15/Part1.js @@ -1,8 +1,12 @@ import { readFileSync } from "fs"; const t0 = performance.now(); -const input = readFileSync("input.txt").toString(); -console.log(input); +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`);