Created
December 11, 2023 05:14
-
-
Save bluepichu/d9448dd963e5bef082a9fd73c61567e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Advent, f, fm, chr, ord } from "advent"; | |
import { Set, Map } from "immutable"; | |
const { compute, computeCheck } = await Advent({ day: 11 }); | |
compute(2, async (input) => { | |
const data = input.parse(f.cGrid()); | |
let rows: number[] = []; | |
for (let i = 0; i < data.length; i++) { | |
if (data[i].every((c) => c === ".")) { | |
// data.splice(i, 0, data[i].map(() => ".")); | |
// i++; | |
rows.push(i); | |
} | |
} | |
let cols: number[] = []; | |
for (let j = 0; j < data[0].length; j++) { | |
if (data.every((row) => row[j] === ".")) { | |
// data.forEach((row) => row.splice(j, 0, ".")); | |
// j++; | |
cols.push(j); | |
} | |
} | |
let coords: [number, number][] = []; | |
for (let i = 0; i < data.length; i++) { | |
for (let j = 0; j < data[i].length; j++) { | |
if (data[i][j] === "#") { | |
coords.push([i, j]); | |
} | |
} | |
} | |
let ans = 0; | |
for (let i = 0; i < coords.length; i++) { | |
for (let j = i+1; j < coords.length; j++) { | |
ans += Math.abs(coords[i][0] - coords[j][0]) + Math.abs(coords[i][1] - coords[j][1]); | |
let rmin = Math.min(coords[i][0], coords[j][0]); | |
let rmax = Math.max(coords[i][0], coords[j][0]); | |
let cmin = Math.min(coords[i][1], coords[j][1]); | |
let cmax = Math.max(coords[i][1], coords[j][1]); | |
ans += 999999 * (rows.filter((r) => rmin <= r && r <= rmax).length); | |
ans += 999999 * (cols.filter((c) => cmin <= c && c <= cmax).length); | |
} | |
} | |
return ans; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment