Skip to content

Commit b68d1b8

Browse files
committed
Working part one
1 parent 97ba081 commit b68d1b8

File tree

6 files changed

+1085
-0
lines changed

6 files changed

+1085
-0
lines changed

2018/23/input.js

Lines changed: 1002 additions & 0 deletions
Large diffs are not rendered by default.

2018/23/manhatten.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const m = (a, b) => {
2+
return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]) + Math.abs(a[2] - b[2]);
3+
}
4+
5+
module.exports = m;

2018/23/part-one.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const distance = require('manhattan');
2+
const input = require('./input');
3+
const cloned_input = JSON.parse(JSON.stringify(input));
4+
5+
cloned_input.sort((a, b) => {
6+
if (a.r < b.r) return -1;
7+
else if (a.r > b.r) return 1;
8+
else return 0;
9+
});
10+
11+
let largest = cloned_input[cloned_input.length - 1];
12+
13+
let in_range = 0;
14+
for (let i = 0; i < input.length - 1; i++) {
15+
let bot = input[i];
16+
if (distance(bot.pos, largest.pos) <= largest.r) {
17+
in_range++;
18+
}
19+
}
20+
21+
console.log(in_range);

2018/23/part-two.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const distance = require('manhattan');
2+
const input = require('./input');
3+
const cloned_input = JSON.parse(JSON.stringify(input));
4+
5+
xs = cloned_input.map(p => p[0]);
6+
ys = cloned_input.map(p => p[1]);
7+
zs = cloned_input.map(p => p[2]);
8+
9+
const sortNum = (a, b) => {
10+
if (a < b) return -1;
11+
else if (a > b) return 1;
12+
else return 0;
13+
};
14+
15+
xs.sort(sortNum);
16+
ys.sort(sortNum);
17+
zs.sort(sortNum);
18+
19+
const min_x = xs[0];
20+
const max_x = xs[xs.length - 1];
21+
22+
const min_y = ys[0];
23+
const max_y = ys[ys.length - 1];
24+
25+
const min_z = zs[0];
26+
const max_z = zs[zs.length - 1];
27+
28+
let largest = cloned_input[cloned_input.length - 1];
29+
30+
let in_range = 0;
31+
for (let i = 0; i < input.length - 1; i++) {
32+
let bot = input[i];
33+
if (distance(bot.pos, largest.pos) <= largest.r) {
34+
in_range++;
35+
}
36+
}
37+
38+
console.log(in_range);

2018/23/sample-input.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = [
2+
{ pos: [0, 0, 0], r: 4 },
3+
{ pos: [1, 0, 0], r: 1 },
4+
{ pos: [4, 0, 0], r: 3 },
5+
{ pos: [0, 2, 0], r: 1 },
6+
{ pos: [0, 5, 0], r: 3 },
7+
{ pos: [0, 0, 3], r: 1 },
8+
{ pos: [1, 1, 1], r: 1 },
9+
{ pos: [1, 1, 2], r: 1 },
10+
{ pos: [1, 3, 1], r: 1 },
11+
];

2018/23/sample-input2.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = [
2+
{ pos: [10, 12, 12], r: 2 },
3+
{ pos: [12, 14, 12], r: 2 },
4+
{ pos: [16, 12, 12], r: 4 },
5+
{ pos: [14, 14, 14], r: 6 },
6+
{ pos: [50, 50, 50], r: 200 },
7+
{ pos: [10, 10, 10], r: 5 },
8+
];

0 commit comments

Comments
 (0)