2018 d3 all by myself
This commit is contained in:
parent
d511a492e1
commit
574a532298
1259
2018/3/input.txt
Normal file
1259
2018/3/input.txt
Normal file
File diff suppressed because it is too large
Load diff
20
2018/3/part1.js
Normal file
20
2018/3/part1.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
const fs = require('fs');
|
||||
|
||||
let input = fs.readFileSync('input.txt', 'utf-8');
|
||||
let grid = {};
|
||||
|
||||
for (const line of input.split('\n')) {
|
||||
[rule,
|
||||
id,
|
||||
left,
|
||||
top,
|
||||
width,
|
||||
height] = line.match(/#(\d+) @ (\d+),(\d+): (\d+)x(\d+)/).map(Number);
|
||||
for (let x = left; x < left + width; x++) {
|
||||
for (let y = top; y < top + height; y++) {
|
||||
grid[`${x},${y}`] = (grid[`${x},${y}`] || 0) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(Object.values(grid).filter(v => v > 1).length);
|
25
2018/3/part2.js
Normal file
25
2018/3/part2.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
const fs = require('fs');
|
||||
|
||||
let input = fs.readFileSync('input.txt', 'utf-8');
|
||||
let grid = {};
|
||||
let claims = []
|
||||
|
||||
for (let line of input.split('\n')) {
|
||||
[rule,
|
||||
id,
|
||||
left,
|
||||
top,
|
||||
width,
|
||||
height] = line.match(/#(\d+) @ (\d+),(\d+): (\d+)x(\d+)/).map(Number);
|
||||
claims[id] = true;
|
||||
for (let x = left; x < left + width; x++) {
|
||||
for (let y = top; y < top + height; y++) {
|
||||
if (grid[`${x},${y}`]) {
|
||||
claims[grid[`${x},${y}`]] = false;
|
||||
claims[id] = false;
|
||||
}
|
||||
grid[`${x},${y}`] = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(Object.entries(claims).filter(v => v[1])[0][0]);
|
Loading…
Reference in a new issue