45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
import * as R from "remeda";
|
|
|
|
import { readFile } from "../05/part1.js";
|
|
|
|
import V from '@yanick/vyktor';
|
|
|
|
const readInput = (...args) =>
|
|
R.pipe(
|
|
readFile(...args),
|
|
(lines) => lines.split("\n"),
|
|
R.compact, // remove last line
|
|
R.map(line => line.match(/x=.*?y=\d+/g).map(str =>
|
|
str.match(/-?\d+/g).map(x => parseInt(x))).map(
|
|
coords => V(coords)
|
|
)
|
|
));
|
|
|
|
export const puzzleInput = readInput(import.meta.url, "input");
|
|
export const sample = readInput(import.meta.url, "sample");
|
|
|
|
export const unbeaconAtLine = targetLine => R.createPipe(
|
|
R.map( ([x,y]) => [ x, x.manhattanDistance(y) ] ),
|
|
R.filter(
|
|
e => (
|
|
( e[0].y - e[1] <= targetLine) &&
|
|
( e[0].y + e[1] >= targetLine)
|
|
)
|
|
),
|
|
R.map(
|
|
e => {
|
|
const l = e[1] - Math.abs(targetLine - e[0].y);
|
|
|
|
return R.range(
|
|
e[0].x - l,
|
|
e[0].x + l,
|
|
) }
|
|
),
|
|
R.flatten,
|
|
R.uniq,
|
|
x => x.length
|
|
|
|
);
|
|
|
|
export default unbeaconAtLine(2000000);
|