15.1, but not 15.2
This commit is contained in:
parent
c1e0aa3c9a
commit
7cc2ed62a6
3 changed files with 83 additions and 0 deletions
14
2022/15/example.txt
Normal file
14
2022/15/example.txt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
Sensor at x=2, y=18: closest beacon is at x=-2, y=15
|
||||||
|
Sensor at x=9, y=16: closest beacon is at x=10, y=16
|
||||||
|
Sensor at x=13, y=2: closest beacon is at x=15, y=3
|
||||||
|
Sensor at x=12, y=14: closest beacon is at x=10, y=16
|
||||||
|
Sensor at x=10, y=20: closest beacon is at x=10, y=16
|
||||||
|
Sensor at x=14, y=17: closest beacon is at x=10, y=16
|
||||||
|
Sensor at x=8, y=7: closest beacon is at x=2, y=10
|
||||||
|
Sensor at x=2, y=0: closest beacon is at x=2, y=10
|
||||||
|
Sensor at x=0, y=11: closest beacon is at x=2, y=10
|
||||||
|
Sensor at x=20, y=14: closest beacon is at x=25, y=17
|
||||||
|
Sensor at x=17, y=20: closest beacon is at x=21, y=22
|
||||||
|
Sensor at x=16, y=7: closest beacon is at x=15, y=3
|
||||||
|
Sensor at x=14, y=3: closest beacon is at x=15, y=3
|
||||||
|
Sensor at x=20, y=1: closest beacon is at x=15, y=3
|
46
2022/15/index.js
Normal file
46
2022/15/index.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
const fs = require('fs/promises');
|
||||||
|
|
||||||
|
const sum = (arr) => arr.reduce((total, num) => total+num, 0);
|
||||||
|
const arrayOfLength = n => Array.from(Array(n).keys()).map(() => {});
|
||||||
|
|
||||||
|
const parseXY = str => str.match(/x=(.*), y=(.*)$/).slice(1).map(x => BigInt(x));
|
||||||
|
|
||||||
|
const ROW = 2000000n;
|
||||||
|
|
||||||
|
const abs = x => x < 0n ? x * -1n : x;
|
||||||
|
const main = async () => {
|
||||||
|
const input = (await fs.readFile("./input.txt", 'utf8')).split("\n").slice(0, -1);
|
||||||
|
console.log(input);
|
||||||
|
const sets = input.map(row => row.split(": ").map(parseXY));
|
||||||
|
const map = new Set();
|
||||||
|
|
||||||
|
|
||||||
|
const getDistance = (x1, y1, x2, y2) => abs(x1 - x2) + abs(y1 - y2);
|
||||||
|
|
||||||
|
const fillRow = (centerX, radius) => {
|
||||||
|
console.log("Fill radius: ", radius);
|
||||||
|
for(let i = centerX - radius; i <= centerX + radius; ++i) {
|
||||||
|
map.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let [[x, y], b] of sets) {
|
||||||
|
const radius = getDistance(x, y, ...b);
|
||||||
|
const halfWidth = radius - abs(ROW - y)
|
||||||
|
if(halfWidth > 0) {
|
||||||
|
fillRow(x, halfWidth);
|
||||||
|
}else {
|
||||||
|
console.log("Skip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let [_, b] of sets) {
|
||||||
|
if(b[1] === ROW) {
|
||||||
|
map.delete(b[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("ANSWER: ", map.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
23
2022/15/input.txt
Normal file
23
2022/15/input.txt
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
Sensor at x=3907621, y=2895218: closest beacon is at x=3790542, y=2949630
|
||||||
|
Sensor at x=1701067, y=3075142: closest beacon is at x=2275951, y=3717327
|
||||||
|
Sensor at x=3532369, y=884718: closest beacon is at x=2733699, y=2000000
|
||||||
|
Sensor at x=2362427, y=41763: closest beacon is at x=2999439, y=-958188
|
||||||
|
Sensor at x=398408, y=3688691: closest beacon is at x=2275951, y=3717327
|
||||||
|
Sensor at x=1727615, y=1744968: closest beacon is at x=2733699, y=2000000
|
||||||
|
Sensor at x=2778183, y=3611924: closest beacon is at x=2275951, y=3717327
|
||||||
|
Sensor at x=2452818, y=2533012: closest beacon is at x=2733699, y=2000000
|
||||||
|
Sensor at x=88162, y=2057063: closest beacon is at x=-109096, y=390805
|
||||||
|
Sensor at x=2985370, y=2315046: closest beacon is at x=2733699, y=2000000
|
||||||
|
Sensor at x=2758780, y=3000106: closest beacon is at x=3279264, y=2775610
|
||||||
|
Sensor at x=3501114, y=3193710: closest beacon is at x=3790542, y=2949630
|
||||||
|
Sensor at x=313171, y=1016326: closest beacon is at x=-109096, y=390805
|
||||||
|
Sensor at x=3997998, y=3576392: closest beacon is at x=3691556, y=3980872
|
||||||
|
Sensor at x=84142, y=102550: closest beacon is at x=-109096, y=390805
|
||||||
|
Sensor at x=3768533, y=3985372: closest beacon is at x=3691556, y=3980872
|
||||||
|
Sensor at x=2999744, y=3998031: closest beacon is at x=3691556, y=3980872
|
||||||
|
Sensor at x=3380504, y=2720962: closest beacon is at x=3279264, y=2775610
|
||||||
|
Sensor at x=3357940, y=3730208: closest beacon is at x=3691556, y=3980872
|
||||||
|
Sensor at x=1242851, y=838744: closest beacon is at x=-109096, y=390805
|
||||||
|
Sensor at x=3991401, y=2367688: closest beacon is at x=3790542, y=2949630
|
||||||
|
Sensor at x=3292286, y=2624894: closest beacon is at x=3279264, y=2775610
|
||||||
|
Sensor at x=2194423, y=3990859: closest beacon is at x=2275951, y=3717327
|
Loading…
Reference in a new issue