diff --git a/functions/src/Grid.ts b/functions/src/Grid.ts index eb88a56..e70a1ec 100644 --- a/functions/src/Grid.ts +++ b/functions/src/Grid.ts @@ -31,7 +31,7 @@ class Grid { return this.data[this.index(x, y)]; } - setAt(x: number, y: number, value: T) { + setAt(x: number, y: number, value: T): void { if (!this.isInBounds(x, y)) { throw Error(`Invalid coordinate: (${x}, ${y})`); @@ -53,7 +53,7 @@ class Grid { return x >= 0 && x < this.maxX && y >= 0 && y < this.maxY; } - inBoundsNeighbors(x: number, y: number, includeDiagonal: boolean = false): Vector2[] { + inBoundsNeighbors(x: number, y: number, includeDiagonal = false): Vector2[] { const res = [ new Vector2(x + 1, y), @@ -75,7 +75,7 @@ class Grid { /** * Pastes the given grid into this grid, with it's top left position at the given coordinate */ - paste(grid: Grid, posX: number, posY: number) { + paste(grid: Grid, posX: number, posY: number): void { if (posX + grid.maxX > this.maxX || posY + grid.maxY > this.maxY) throw Error(`Can't paste grid at (${posX}, ${posY}), this grid is not big enough`); diff --git a/functions/src/day14.ts b/functions/src/day14.ts index ec375b2..d80ae8f 100644 --- a/functions/src/day14.ts +++ b/functions/src/day14.ts @@ -76,7 +76,7 @@ class Day14 implements Day { const { orig, mapping } = Day14.parseInput(input); - let counts: CharCounts = {}; + const counts: CharCounts = {}; const cache = new Map(); for (let i = 0; i < orig.length - 1; i++) { @@ -120,7 +120,7 @@ class Day14 implements Day { } - mergeIntoLeft(left: CharCounts, right: CharCounts) { + mergeIntoLeft(left: CharCounts, right: CharCounts): void { for (const rightKey in right) { if (rightKey in left) { @@ -131,7 +131,7 @@ class Day14 implements Day { } } - addOne(char: string, counts: CharCounts) { + addOne(char: string, counts: CharCounts): void { if (char in counts) { counts[char]++; diff --git a/functions/src/day15.ts b/functions/src/day15.ts index 261ccc6..4f8bd10 100644 --- a/functions/src/day15.ts +++ b/functions/src/day15.ts @@ -42,7 +42,10 @@ class Day15 implements Day { // Simulate a priority queue on distance: searchStack.sort((a, b) => distances.at(b.x, b.y) - distances.at(a.x, a.y)); - const cur = searchStack.pop()!; + const cur = searchStack.pop(); + + if (!cur) throw Error("???"); + if (cur.x === destination.x && cur.y === destination.y) { break; } diff --git a/functions/src/day16.ts b/functions/src/day16.ts index 47f9065..c0e47c9 100644 --- a/functions/src/day16.ts +++ b/functions/src/day16.ts @@ -92,7 +92,7 @@ class Packet { return input.split("").map(s => parseInt(s, 16).toString(2).padStart(4, "0")).join(""); } - static parseBinaryInput(binaryInput: string, start: number = 0): Packet { + static parseBinaryInput(binaryInput: string, start = 0): Packet { const version = parseInt(binaryInput.substr(start, Packet.VERSION_LENGTH), 2); const type = parseInt(binaryInput.substr(start + Packet.VERSION_LENGTH, Packet.TYPE_LENGTH), 2);