25 lines
653 B
JavaScript
25 lines
653 B
JavaScript
import * as R from "remeda";
|
|
import V from '@yanick/vyktor';
|
|
|
|
export const findBeacon = max => entries => {
|
|
|
|
const nonGrata = R.uniqBy(R.flatten(entries), (x) => x.toString());;
|
|
|
|
const deadZones = R.map( entries, ([x,y]) => [ x, x.manhattanDistance(y) ] );
|
|
|
|
for ( let x =0; x <= max; x++ ) {
|
|
for ( let y =0; y <= max; y++ ) {
|
|
if( nonGrata.some( p => p.x===x && p.y===y ) ) continue;
|
|
|
|
const v = V(x,y);
|
|
if( deadZones.some(
|
|
d => d[0].manhattanDistance( v ) <= d[1]
|
|
) ) continue;
|
|
|
|
return x * 4000000 + y;
|
|
}
|
|
}
|
|
}
|
|
|
|
export default findBeacon(4000000);
|