mirror of
https://github.com/Baipyrus/AoC-23.git
synced 2024-12-26 12:01:45 +00:00
calc hashes, sum up
This commit is contained in:
parent
774fd15ec4
commit
d6d3a06b85
@ -1,8 +1,12 @@
|
|||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
const t0 = performance.now();
|
const t0 = performance.now();
|
||||||
|
|
||||||
const input = readFileSync("input.txt").toString();
|
const input = readFileSync("input.txt").toString().split("\n")[0].split(",");
|
||||||
console.log(input);
|
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();
|
const t1 = performance.now();
|
||||||
console.log(`Runtime: ${t1 - t0}ms`);
|
console.log(`Runtime: ${t1 - t0}ms`);
|
||||||
|
Loading…
Reference in New Issue
Block a user