2022-12-15 19:35:55 +00:00
|
|
|
import * as R from "remeda";
|
2022-12-18 18:39:06 +00:00
|
|
|
import V from '@yanick/vyktor';
|
2022-12-15 19:35:55 +00:00
|
|
|
|
2022-12-18 18:39:06 +00:00
|
|
|
export const findBeacon = max => entries => {
|
2022-12-15 19:35:55 +00:00
|
|
|
|
2022-12-18 18:39:06 +00:00
|
|
|
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);
|