solution: 2025/4

Signed-off-by: Alix von Schirp <github@avonschirp.bootmedia.de>
This commit is contained in:
2025-12-04 07:11:27 +01:00
parent 0d0b85d4af
commit ad47193543
2 changed files with 81 additions and 0 deletions

35
src/2025/4/1/index.ts Normal file
View File

@@ -0,0 +1,35 @@
export default async function runner(inputPath: string){
const input = (await Bun.file(inputPath).text()).trimEnd();
let accessible = 0;
input.split("\n").map(value => value.trim()).forEach((line, lineIndex, lineArray) => {
line.split("").forEach((char, charIndex, charArray) => {
if(char === ".") {
return;
}
let touch = 0;
for(let xOffset = -1; xOffset<2; xOffset++) {
for (let yOffset = -1; yOffset<2; yOffset++) {
if(xOffset === 0 && yOffset === 0) continue;
let x = charIndex+xOffset;
let y = lineIndex+yOffset;
if(x<0 || y<0 || y>=lineArray.length || x>=charArray.length) {
continue;
}
if((lineArray[y]?.charAt(x) ?? "") === "@"){
touch++;
}
}
}
if(touch<4) {
accessible++;
return;
}
})
})
console.log(accessible);
}

46
src/2025/4/2/index.ts Normal file
View File

@@ -0,0 +1,46 @@
export default async function runner(inputPath: string) {
let input = (await Bun.file(inputPath).text()).trimEnd();
let accessible = 0;
let remove = 0;
do {
accessible = 0;
let newInput = ""
input.split("\n").map(value => value.trim()).forEach((line, lineIndex, lineArray) => {
line.split("").forEach((char, charIndex, charArray) => {
if (char === ".") {
newInput = newInput + ".";
return;
}
let touch = 0;
for (let xOffset = -1; xOffset < 2; xOffset++) {
for (let yOffset = -1; yOffset < 2; yOffset++) {
if (xOffset === 0 && yOffset === 0) continue;
let x = charIndex + xOffset;
let y = lineIndex + yOffset;
if (x < 0 || y < 0 || y >= lineArray.length || x >= charArray.length) {
continue;
}
if ((lineArray[y]?.charAt(x) ?? "") === "@") {
touch++;
}
}
}
if (touch < 4) {
accessible++;
remove++;
newInput = newInput + "."
return;
}
newInput = newInput + "@"
})
newInput = newInput + "\n"
})
input = newInput
} while (accessible !== 0)
console.log(remove);
}