adventOfCode/2022/3/part1.ts
2023-12-02 10:46:52 +01:00

17 lines
No EOL
595 B
TypeScript

const input = Deno.readTextFileSync("input");
const priority = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
let sum = 0;
for(const line of input.split("\n")) {
const firstHalf = line.slice(0, line.length / 2);
const secondHalf = line.slice(line.length / 2);
console.log(firstHalf, secondHalf, firstHalf.length, secondHalf.length);
const sharedLetter = firstHalf.split("").find((letter) => secondHalf.includes(letter));
sum += priority.indexOf(sharedLetter!) + 1;
console.log(sharedLetter, priority.indexOf(sharedLetter!) + 1);
}
console.log(sum)