aoc-2023/day_15/solve.ts
2024-12-09 22:41:02 +09:00

17 lines
424 B
TypeScript

const input = await Deno.readTextFile("input.txt");
const inputs = input.split(",");
function hash(s: string){
let ret = 0;
for (let i = 0; i < s.length; i++) {
const ch = s.charCodeAt(i);
ret += ch;
ret *= 17;
ret %= 256;
}
return ret;
}
console.log(hash("HASH"), 52);
// console.log(inputs.map(x=> hash(x)))
console.log(inputs.map(x=> hash(x)).reduce((a, b) => a + b, 0));