Platform
Solutions
Resources
Pricing
Sign in
Sign up
Emanuel Feld
Workspace
Fork
Published
Advent of Code 2018
By
Emanuel Feld
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cloth
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
conflictingAreaSize
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
hasOverlaps
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
nonOverlappingClaimId
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
input
Edit
Pin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete