This commit is contained in:
2025-11-11 06:34:09 +01:00
parent d7160c7bed
commit b1653348a2
2 changed files with 91 additions and 0 deletions

46
src/2015/6/1/index.ts Normal file
View File

@@ -0,0 +1,46 @@
export default async function runner(inputPath: string) {
const input = await Bun.file(inputPath).text();
const lights: boolean[][] = []
for(let x = 0; x<1000; x++){
lights[x] = [];
for(let y = 0; y<1000; y++){
lights[x]![y]=false;
}
}
input.split("\n").forEach(line => {
if(line.trim() === '') return;
const [_1, command, x1, y1, x2, y2, _2] = line.split(/^(\w*(?:\s\w*)?)\s(\d*),(\d*)\s(?:\w*)\s(\d*),(\d*)$/gm);
console.log(line, x1, x2, y1, y2, command)
for(let x = parseInt(x1!); x<=parseInt(x2!); x++){
for(let y = parseInt(y1!); y<=parseInt(y2!); y++){
switch (command) {
case "turn on":
lights[x]![y]=true;
break;
case "turn off":
lights[x]![y]=false;
break;
case "toggle":
lights[x]![y]=!lights[x]![y];
break;
}
}
}
})
let cnt = 0;
for(let x = 0; x<1000; x++){
for(let y = 0; y<1000; y++){
if (lights[x]![y]) cnt++;
}
}
console.log(cnt)
}

45
src/2015/6/2/index.ts Normal file
View File

@@ -0,0 +1,45 @@
export default async function runner(inputPath: string) {
const input = await Bun.file(inputPath).text();
const lights: number[][] = []
for(let x = 0; x<1000; x++){
lights[x] = [];
for(let y = 0; y<1000; y++){
lights[x]![y]=0;
}
}
input.split("\n").forEach(line => {
if(line.trim() === '') return;
const [_1, command, x1, y1, x2, y2, _2] = line.split(/^(\w*(?:\s\w*)?)\s(\d*),(\d*)\s(?:\w*)\s(\d*),(\d*)$/gm);
for(let x = parseInt(x1!); x<=parseInt(x2!); x++){
for(let y = parseInt(y1!); y<=parseInt(y2!); y++){
switch (command) {
case "turn on":
lights[x]![y]!+=1;
break;
case "turn off":
lights[x]![y]! -= 1;
lights[x]![y]! = Math.max(lights[x]![y]!, 0)
break;
case "toggle":
lights[x]![y]!+=2;
break;
}
}
}
})
let cnt = 0;
for(let x = 0; x<1000; x++){
for(let y = 0; y<1000; y++){
cnt+=lights[x]![y]!;
}
}
console.log(cnt)
}