Initialize repo for 2025

This commit is contained in:
Eric Wagoner
2025-12-01 10:21:03 -05:00
parent 149a4f7278
commit 95e4af9eb3
13 changed files with 25 additions and 1981 deletions

View File

@@ -1,102 +1,27 @@
const fs = require('fs');
import { readFileSync } from 'node:fs';
// const inputArray = fs.readFileSync('sample.txt').toString().split("\n");
let inputArray = fs.readFileSync('input.txt').toString().split("\n");
let allInts = [];
let sum = 0;
const inputArray = readFileSync('sample.txt').toString().split("\n");
// const inputArray = fs.readFileSync('input.txt').toString().split("\n");
// Part One
for (i in inputArray) {
const forwards = inputArray[i];
const backwards = inputArray[i].split("").reverse().join("");
let firstInt;
let lastInt;
for (j in forwards) {
if (parseInt(forwards[j])) {
firstInt = parseInt(forwards[j]);
break;
}
}
for (j in backwards) {
if (parseInt(backwards[j])) {
lastInt = parseInt(backwards[j]);
break;
}
}
allInts.push(parseInt(`${firstInt}${lastInt}`));
const contents = inputArray[i].split(" ");
}
sum = allInts.reduce((a, b) => a + b, 0);
console.log(sum);
console.log();
// Part Two
// inputArray = fs.readFileSync('sample2.txt').toString().split("\n");
allInts = [];
for (i in inputArray) {
let forwards = inputArray[i];
let needsParsed = true;
while (needsParsed) {
for (j in forwards) {
if (forwards[j] === "o" && forwards.substring(j,parseInt(parseInt(j)+parseInt(3))) === "one") {
forwards = forwards.substring(0, j) + "1" + forwards.substring(parseInt(parseInt(j)+parseInt(1)));
break;
} else if (forwards[j] === "t" && forwards.substring(j,parseInt(parseInt(j)+parseInt(3))) === "two") {
forwards = forwards.substring(0, j) + "2" + forwards.substring(parseInt(parseInt(j)+parseInt(1)));
break;
} else if (forwards[j] === "t" && forwards.substring(j,parseInt(parseInt(j)+parseInt(5))) === "three") {
forwards = forwards.substring(0, j) + "3" + forwards.substring(parseInt(parseInt(j)+parseInt(1)));
break;
} else if (forwards[j] === "f" && forwards.substring(j,parseInt(parseInt(j)+parseInt(4))) === "four") {
forwards = forwards.substring(0, j) + "4" + forwards.substring(parseInt(parseInt(j)+parseInt(1)));
break;
} else if (forwards[j] === "f" && forwards.substring(j,parseInt(parseInt(j)+parseInt(4))) === "five") {
forwards = forwards.substring(0, j) + "5" + forwards.substring(parseInt(parseInt(j)+parseInt(1)));
break;
} else if (forwards[j] === "s" && forwards.substring(j,parseInt(parseInt(j)+parseInt(3))) === "six") {
forwards = forwards.substring(0, j) + "6" + forwards.substring(parseInt(parseInt(j)+parseInt(1)));
break;
} else if (forwards[j] === "s" && forwards.substring(j,parseInt(parseInt(j)+parseInt(5))) === "seven") {
forwards = forwards.substring(0, j) + "7" + forwards.substring(parseInt(parseInt(j)+parseInt(1)));
break;
} else if (forwards[j] === "e" && forwards.substring(j,parseInt(parseInt(j)+parseInt(5))) === "eight") {
forwards = forwards.substring(0, j) + "8" + forwards.substring(parseInt(parseInt(j)+parseInt(1)));
break;
} else if (forwards[j] === "n" && forwards.substring(j,parseInt(parseInt(j)+parseInt(4))) === "nine") {
forwards = forwards.substring(0, j) + "9" + forwards.substring(parseInt(parseInt(j)+parseInt(1)));
break;
} else if (parseInt(j) === forwards.length - 1) {
needsParsed = false;
}
}
}
const contents = inputArray[i].split(" ");
backwards = forwards.split("").reverse().join("");
let firstInt;
let lastInt;
for (j in forwards) {
if (parseInt(forwards[j])) {
firstInt = parseInt(forwards[j]);
break;
}
}
for (j in backwards) {
if (parseInt(backwards[j])) {
lastInt = parseInt(backwards[j]);
break;
}
}
allInts.push(parseInt(`${firstInt}${lastInt}`));
}
sum = allInts.reduce((a, b) => a + b, 0);
console.log(sum);
console.log();
// functions

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +0,0 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

View File

@@ -1,7 +0,0 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen