part 2, crummy
This commit is contained in:
parent
69f0bf3f1c
commit
0a281c084c
@ -11,7 +11,7 @@ const readInput = (...args) =>
|
||||
readFile(...args),
|
||||
(lines) => lines.split("\n"),
|
||||
R.compact, // remove last line
|
||||
R.map(line => line.match(/x=.*?y=\d+/g).map(str =>
|
||||
R.map(line => line.match(/x=-?.*?y=-?\d+/g).map(str =>
|
||||
str.match(/-?\d+/g).map(x => parseInt(x))).map(
|
||||
coords => V(coords)
|
||||
)
|
||||
|
@ -1,4 +1,24 @@
|
||||
import * as R from "remeda";
|
||||
import V from '@yanick/vyktor';
|
||||
|
||||
export const findBeacon = max => entries => {
|
||||
|
||||
export default () => {};
|
||||
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);
|
||||
|
@ -2,7 +2,7 @@ import { test, expect, describe } from "vitest";
|
||||
|
||||
import { expectSolution } from "../01/main.js";
|
||||
import part1, { sample, puzzleInput, unbeaconAtLine } from "./part1.js";
|
||||
import part2 from "./part2.js";
|
||||
import part2, { findBeacon } from "./part2.js";
|
||||
|
||||
describe("part 1", () => {
|
||||
test('readInput', () => {
|
||||
@ -19,7 +19,10 @@ describe("part 1", () => {
|
||||
});
|
||||
|
||||
describe("part 2", () => {
|
||||
test.todo("solution", () => {
|
||||
test('sample', () => {
|
||||
expect(findBeacon(20)(sample)).toEqual(56000011);
|
||||
});
|
||||
test.only("solution", () => {
|
||||
expectSolution(part2(puzzleInput)).toEqual("TODO");
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user