generated from eric/adventofcode2023
day two part one
This commit is contained in:
25
02/code.js
25
02/code.js
@@ -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("-");
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user