Platform
Resources
Pricing
Sign in
Get started
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
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cloth
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
conflictingAreaSize
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
hasOverlaps
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nonOverlappingClaimId
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
input
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML