solution: 2025/4
Signed-off-by: Alix von Schirp <github@avonschirp.bootmedia.de>
This commit is contained in:
35
src/2025/4/1/index.ts
Normal file
35
src/2025/4/1/index.ts
Normal 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
46
src/2025/4/2/index.ts
Normal 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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user