55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
|
const fs = require('fs/promises');
|
||
|
|
||
|
const sum = (arr) => arr.reduce((total, num) => total+num, 0);
|
||
|
const arrayOfLength = n => Array.from(Array(n).keys()).map(() => {});
|
||
|
//minus
|
||
|
const keypress = async () => {
|
||
|
process.stdin.setRawMode(true)
|
||
|
return new Promise(resolve => process.stdin.once('data', data => {
|
||
|
const byteArray = [...data]
|
||
|
if (byteArray.length > 0 && byteArray[0] === 3) {
|
||
|
console.log('^C')
|
||
|
process.exit(1)
|
||
|
}
|
||
|
process.stdin.setRawMode(false)
|
||
|
resolve()
|
||
|
}))
|
||
|
}
|
||
|
|
||
|
const coords = ([x, y, z]) => `${x},${y},${z}`;
|
||
|
|
||
|
const main = async () => {
|
||
|
const input = (await fs.readFile("./input.txt", 'utf8')).slice(0, -1).split("\n");
|
||
|
const scan = input.reduce((s, point) => {
|
||
|
s[point] = true;
|
||
|
return s;
|
||
|
}, {});
|
||
|
|
||
|
|
||
|
const points = input.map(p => p.split(",").map(x => parseInt(x)));
|
||
|
|
||
|
let surfaceCount = 0;
|
||
|
|
||
|
for(const [x, y, z] of points) {
|
||
|
const possibleNeighbors = [
|
||
|
[0, 0, 1],
|
||
|
[0, 0, -1],
|
||
|
[0, 1, 0],
|
||
|
[0, -1, 0],
|
||
|
[1, 0, 0],
|
||
|
[-1, 0, 0]
|
||
|
].map(([dx, dy, dz]) => ([x + dx, y + dy, z + dz]));
|
||
|
|
||
|
for(const n of possibleNeighbors) {
|
||
|
if(!scan[coords(n)]) {
|
||
|
surfaceCount++
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
console.log("Answer: ", surfaceCount);
|
||
|
|
||
|
}
|
||
|
|
||
|
main();
|