From 309c59b682204a4b0949225c7199970c7469d230 Mon Sep 17 00:00:00 2001 From: Dallin Stevens Date: Wed, 3 Dec 2025 23:33:46 -0700 Subject: [PATCH 1/3] day 05 --- .../communitySolutions/05/dallinstevens.md | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/content/communitySolutions/05/dallinstevens.md diff --git a/src/content/communitySolutions/05/dallinstevens.md b/src/content/communitySolutions/05/dallinstevens.md new file mode 100644 index 0000000..c15dbaf --- /dev/null +++ b/src/content/communitySolutions/05/dallinstevens.md @@ -0,0 +1,104 @@ +--- +descriptions: ["deno"] +--- + +### 2025 Solution Deno + +```Deno +interface Coordinates { + x: number; + y: number; +} + +class Canvas { + + private commands: string[]; + private grid: string[][]; + private currentPosition: Coordinates; + + constructor(commands: string[]) { + this.commands = commands; + this.grid = []; + this.currentPosition = { x: 0, y: 0 }; + } + + private ensureGridSize() { + if (this.currentPosition.y >= this.grid.length) { + const newColsNeeded = this.currentPosition.y - this.grid.length + 1; + for (let i = 0; i < newColsNeeded; i++) { + this.grid.push([" "]); + } + } + if (this.currentPosition.x > this.grid[this.currentPosition.y].length) { + const newRowsNeeded = this.currentPosition.x - this.grid[this.currentPosition.y].length; + for (let i = 0; i < newRowsNeeded; i++) { + this.grid[this.currentPosition.y].push(" "); + } + } + } + + private moveX(amount: number) { + this.currentPosition.x += amount; + if (this.currentPosition.x < 0) { + throw new Error("Negative X Value. Out of bounds"); + } + } + + private moveY(amount: number) { + this.currentPosition.y += amount; + if (this.currentPosition.x < 0) { + throw new Error("Negative Y Value. Out of bounds"); + } + } + + private printValue(value: string) { + this.ensureGridSize(); + this.grid[this.currentPosition.y][this.currentPosition.x] = value; + } + + public executeCommands() { + for (const command of this.commands) { + console.log(command); + if (command == "P-") { + console.clear(); + } + if (command == "LR") { + this.currentPosition = { x: 0, y: 0 }; + } + else { + switch (command[0]) { + case "U": + this.moveY(-Number(command.slice(1))); + break; + case "D": + this.moveY(Number(command.slice(1))); + break; + case "L": + this.moveX(-Number(command.slice(1))); + break; + case "R": + this.moveX(Number(command.slice(1))); + break; + case "P": + this.printValue(command.slice(1)); + break; + } + } + } + } + + public printGrid() { + for (const row of this.grid) { + console.log(row.join("")); + } + } +} + +if (import.meta.main) { + const commands = (await Deno.readTextFile("5.txt")).split("\n"); + + const canvas = new Canvas(commands); + canvas.executeCommands(); + canvas.printGrid(); +} +``` From 6f8fce1654c3ebb272bbe78575fbbb172ece6ef2 Mon Sep 17 00:00:00 2001 From: Dallin Stevens Date: Wed, 3 Dec 2025 23:48:53 -0700 Subject: [PATCH 2/3] ts --- src/content/communitySolutions/05/dallinstevens.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/communitySolutions/05/dallinstevens.md b/src/content/communitySolutions/05/dallinstevens.md index c15dbaf..b8e2bb4 100644 --- a/src/content/communitySolutions/05/dallinstevens.md +++ b/src/content/communitySolutions/05/dallinstevens.md @@ -4,7 +4,7 @@ descriptions: ["deno"] ### 2025 Solution Deno -```Deno +```ts interface Coordinates { x: number; y: number; From c6bf04fa3490c03f7931c9166fbec0febf653f6b Mon Sep 17 00:00:00 2001 From: Dallin Stevens Date: Thu, 4 Dec 2025 00:00:04 -0700 Subject: [PATCH 3/3] ran prettier --- src/content/communitySolutions/05/dallinstevens.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/content/communitySolutions/05/dallinstevens.md b/src/content/communitySolutions/05/dallinstevens.md index b8e2bb4..9d89344 100644 --- a/src/content/communitySolutions/05/dallinstevens.md +++ b/src/content/communitySolutions/05/dallinstevens.md @@ -11,7 +11,6 @@ interface Coordinates { } class Canvas { - private commands: string[]; private grid: string[][]; private currentPosition: Coordinates; @@ -30,13 +29,14 @@ class Canvas { } } if (this.currentPosition.x > this.grid[this.currentPosition.y].length) { - const newRowsNeeded = this.currentPosition.x - this.grid[this.currentPosition.y].length; + const newRowsNeeded = + this.currentPosition.x - this.grid[this.currentPosition.y].length; for (let i = 0; i < newRowsNeeded; i++) { this.grid[this.currentPosition.y].push(" "); } } } - + private moveX(amount: number) { this.currentPosition.x += amount; if (this.currentPosition.x < 0) { @@ -64,8 +64,7 @@ class Canvas { } if (command == "LR") { this.currentPosition = { x: 0, y: 0 }; - } - else { + } else { switch (command[0]) { case "U": this.moveY(-Number(command.slice(1)));