This commit is contained in:
2023-12-15 11:08:20 +01:00
parent 29fe8f2446
commit 5c87dcecd2
2 changed files with 19 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import { open } from 'node:fs/promises';
function getHash(input: string) {
let curr = 0
for (var i = 0; i < input.length; i++) {
curr += input.charCodeAt(i)
curr *= 17
curr %= 256
}
return curr
}
const file = await open('./inputs/15');
for await (const line of file.readLines()) {
console.log(line.split(',').map(getHash).reduce((acc, cur) => acc + cur, 0))
}
+1
View File
File diff suppressed because one or more lines are too long