day two part one

This commit is contained in:
Eric Wagoner
2025-12-02 09:54:27 -05:00
parent a466e30de5
commit 26d828fe1a

View File

@@ -1,22 +1,35 @@
import { readFileSync } from 'node:fs';
const inputArray = readFileSync('sample.txt').toString().split("\n");
// const inputArray = readFileSync('input.txt').toString().split("\n");
//const inputArray = readFileSync('sample.txt').toString().split(",");
const inputArray = readFileSync('input.txt').toString().split(",");
// Part One
for (const element of inputArray) {
const contents = element.split(" ");
let sum = 0;
for (const element of inputArray) {
const contents = element.split("-");
const start = Number.parseInt(contents[0]);
const end = Number.parseInt(contents[1]);
for (let sku = start; sku <= end; sku++) {
const skuString = sku.toString();
const digits = skuString.length
if (digits % 2 === 0) {
if (skuString.slice(0, digits / 2) === skuString.slice(digits / 2)) {
sum += sku;
}
}
}
}
console.log();
console.log(sum);
// Part Two
for (const element of inputArray) {
const contents = element.split(" ");
const contents = element.split("-");
}