Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const input = await Bun.file("input.txt").text();
- const grid = input.split("\n").map((r) => r.split(""));
- let total = 0;
- for (let y = 0; y < grid.length; y++) {
- for (let x = 0; x < grid[0]!.length; x++) {
- if (grid[y]![x] != "@") continue;
- let rolls = 0;
- for (let dy = -1; dy <= 1; dy++) {
- for (let dx = -1; dx <= 1; dx++) {
- if (dy == 0 && dx == 0) continue;
- if (grid[y + dy]?.[x + dx] == "@") rolls++;
- }
- }
- if (rolls < 4) total++;
- }
- }
- console.log("A:", total);
- let totalRemoved = 0;
- while (true) {
- let removed = 0;
- for (let y = 0; y < grid.length; y++) {
- for (let x = 0; x < grid[0]!.length; x++) {
- if (grid[y]![x] != "@") continue;
- let rolls = 0;
- for (let dy = -1; dy <= 1; dy++) {
- for (let dx = -1; dx <= 1; dx++) {
- if (dy == 0 && dx == 0) continue;
- if (grid[y + dy]?.[x + dx] == "@") rolls++;
- }
- }
- if (rolls < 4) {
- grid[y]![x]! = ".";
- removed++;
- }
- }
- }
- if (removed == 0) break;
- totalRemoved += removed;
- }
- console.log("B:", totalRemoved);
Advertisement
Add Comment
Please, Sign In to add comment