Skip to content

Commit

Permalink
Implement litGridCorners
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbicus committed Oct 2, 2024
1 parent be81b70 commit 68a68cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/aoc2015/day18/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getNeighboursPositions,
LightGrid,
LightState,
litGridCorners,
performStep,
} from "./utils.ts";

Expand Down Expand Up @@ -78,3 +79,21 @@ describe("performStep", function () {
assertEquals(performStep(initialGrid, size), expectedGrid);
});
});

describe("litGridCorners", function () {
it("should lit grid corners", function () {
const { grid: initialGrid, size } = fillGrid(`.#.#.#
...##.
#....#
..#...
#.#..#
####..`);
const { grid: expectedGrid } = fillGrid(`##.#.#
...##.
#....#
..#...
#.#..#
####.#`);
assertEquals(litGridCorners(initialGrid, size), expectedGrid);
});
});
12 changes: 12 additions & 0 deletions scripts/aoc2015/day18/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,15 @@ export function performStep(prevGrid: LightGrid, size: number) {
// gets positions all neighbours of a light in a grid
return grid;
}

export function litGridCorners(grid: LightGrid, size: number) {
const cornerPosition = size - 1;
grid.set(getGridKey({ x: 0, y: 0 }), LightState.TurnedOn);
grid.set(getGridKey({ x: 0, y: cornerPosition }), LightState.TurnedOn);
grid.set(getGridKey({ x: cornerPosition, y: 0 }), LightState.TurnedOn);
grid.set(
getGridKey({ x: cornerPosition, y: cornerPosition }),
LightState.TurnedOn,
);
return grid;
}

0 comments on commit 68a68cb

Please sign in to comment.