Skip to content

Commit f835e6d

Browse files
committed
15 initial
1 parent 5b2a3d9 commit f835e6d

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/15/solve.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
11
import { FileReader } from "../common";
22

3+
class Point {
4+
x: number
5+
y: number
6+
constructor(x: number, y: number) {
7+
this.x = x
8+
this.y = y
9+
}
10+
}
11+
12+
class Beacon extends Point {}
13+
14+
class Sensor extends Point {}
15+
16+
const dist = (p1: Point, p2: Point): number => Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y)
17+
318
class Solve15 extends FileReader {
19+
sensorBeacon: Map<Sensor, Beacon> = new Map()
20+
sensorDist: Map<Sensor, number> = new Map()
21+
minX: number = Number.MAX_SAFE_INTEGER
22+
maxX: number = Number.MIN_SAFE_INTEGER
23+
424
constructor() {
525
super();
626
this.readData("src/15/test.data")
727
.then((data) => {
8-
this.process(data.split("\n"));
28+
this.process(data.split("\n"), 10);
929
})
1030
.catch((err) => console.log(err));
1131
}
1232

13-
process = (data: string[]) => {
33+
process = (data: string[], y: number) => {
34+
// Sensor at x=2, y=18: closest beacon is at x=-2, y=15
35+
data.forEach(row => {
36+
const data = row.split(': closest beacon is at x=')
37+
const sensorData = data[0].slice(12).split(', y=')
38+
const beaconData = data[1].split(', y=')
39+
const sensor: Point = new Sensor(+sensorData[0], +sensorData[1])
40+
const beacon: Point = new Beacon(+beaconData[0], +beaconData[1])
41+
console.log(sensor, beacon)
42+
this.sensorBeacon.set(sensor, beacon)
43+
this.sensorDist.set(sensor, dist(sensor, beacon))
44+
})
1445
};
1546
}
1647

0 commit comments

Comments
 (0)