Published
Edited
Dec 8, 2018
Insert cell
Insert cell
data = input.split('\n').map(line => line.match(/\d+/g).map(Number))
Insert cell
Insert cell
cloth = {
let cloth = {};
for (let [n, left, top, width, height] of data) {
for (let x = left; x < left + width; x++) {
for (var y = top; y < top + height; y++) {
cloth[`(${x},${y})`] = (cloth[`(${x},${y})`] || 0) + 1;
}
}
}
return cloth;
}
Insert cell
conflictingAreaSize = Object.values(cloth).filter(claims => claims > 1).length
Insert cell
Insert cell
function hasOverlaps(left, top, width, height) {
for (let x = left; x < left + width; x++) {
for (var y = top; y < top + height; y++) {
if (cloth[`(${x},${y})`] > 1) {
return true;
}
}
}
return false;
}
Insert cell
nonOverlappingClaimId = {
for (let [n, left, top, width, height] of data) {
if (!hasOverlaps(left, top, width, height)) {
return n;
}
}
}
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more