Skip to content

Commit

Permalink
run on prod
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlauer-Hax committed Dec 6, 2024
1 parent 52338ec commit e924829
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions clients/typescript/solutions/S2406.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default class S2406 implements ISolution {
const coords = input.split("\n").map(line => line.split(""));
function tryWith(coords: string[][]): number {
const poss: {x: number, y: number}[] = [];
const turn: {x: number, y: number, t: string}[] = [];
let direction = "up";
const currentPos = { x: 0, y: 0 };
for (const y in coords) {
Expand All @@ -85,8 +86,7 @@ export default class S2406 implements ISolution {
}
poss.push({ x: currentPos.x, y: currentPos.y });
walk: while (true) {
if (poss.length - poss.filter((pos, index) => poss.findIndex(p => p.x === pos.x && p.y === pos.y) === index).length > coords.length * coords[ 0 ].length) {
console.log("probably infinite loop");
if (turn.some((t, i) => turn.findIndex(tt => tt.x === t.x && tt.y === t.y && tt.t === t.t) !== i)) {
return 1;
}
switch (direction) {
Expand All @@ -96,9 +96,9 @@ export default class S2406 implements ISolution {
}
if (coords[ currentPos.y - 1 ][ currentPos.x ] === "#") {
direction = "right";
turn.push({ x: currentPos.x, y: currentPos.y, t: "right" });
} else {
currentPos.y--;
poss.push({ x: currentPos.x, y: currentPos.y });
}
break;
case "right":
Expand All @@ -107,9 +107,9 @@ export default class S2406 implements ISolution {
}
if (coords[ currentPos.y ][ currentPos.x + 1 ] === "#") {
direction = "down";
turn.push({ x: currentPos.x, y: currentPos.y, t: "down" });
} else {
currentPos.x++;
poss.push({ x: currentPos.x, y: currentPos.y });
}
break;
case "down":
Expand All @@ -118,9 +118,9 @@ export default class S2406 implements ISolution {
}
if (coords[ currentPos.y + 1 ][ currentPos.x ] === "#") {
direction = "left";
turn.push({ x: currentPos.x, y: currentPos.y, t: "left" });
} else {
currentPos.y++;
poss.push({ x: currentPos.x, y: currentPos.y });
}
break;
case "left":
Expand All @@ -129,9 +129,9 @@ export default class S2406 implements ISolution {
}
if (coords[ currentPos.y ][ currentPos.x - 1 ] === "#") {
direction = "up";
turn.push({ x: currentPos.x, y: currentPos.y, t: "up" });
} else {
currentPos.x--;
poss.push({ x: currentPos.x, y: currentPos.y });
}
break;

Expand Down

0 comments on commit e924829

Please sign in to comment.