Platform
Resources
Pricing
Sign in
Get started
Michael Cooper
Developer @Observable
Workspace
Fork
Public
Advent of Code 2022
By
Michael Cooper
Edited
Dec 8, 2022
1 fork
Importers
1 star
1
Insert cell
Insert cell
aoc
.
resultTable
(
meta
)
Insert cell
parse
=
aoc
.
lines
(
(
l
)
=>
{
let
match
=
Array
.
from
(
/(\d+)-(\d+),(\d+)-(\d+)/
.
exec
(
l
)
,
Number
)
;
return
{
elf1
:
match
.
slice
(
1
,
3
)
,
elf2
:
match
.
slice
(
3
,
5
)
}
;
}
)
Insert cell
fullContains
=
(
a
,
b
)
=>
(
a
[
0
]
<=
b
[
0
]
&&
a
[
1
]
>=
b
[
1
]
)
||
(
a
[
0
]
>=
b
[
0
]
&&
a
[
1
]
<=
b
[
1
]
)
Insert cell
contains
=
(
a
,
x
)
=>
a
[
0
]
<=
x
&&
a
[
1
]
>=
x
Insert cell
overlaps
=
(
a
,
b
)
=>
fullContains
(
a
,
b
)
||
contains
(
a
,
b
[
0
]
)
||
contains
(
a
,
b
[
1
]
)
||
contains
(
b
,
a
[
0
]
)
||
contains
(
b
,
a
[
1
]
)
Insert cell
function
part1
(
input
)
{
return
input
.
filter
(
(
{
elf1
,
elf2
}
)
=>
fullContains
(
elf1
,
elf2
)
)
.
length
;
}
Insert cell
function
part2
(
input
)
{
return
input
.
filter
(
(
{
elf1
,
elf2
}
)
=>
overlaps
(
elf1
,
elf2
)
)
.
length
;
}
Insert cell
inputs
=
(
{
test
:
`2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8`
,
real
:
await
FileAttachment
(
"input"
)
.
text
(
)
}
)
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
parse
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
fullContains
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
contains
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
overlaps
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
part1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
part2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
inputs
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
meta
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML