Platform
Resources
Pricing
Sign in
Get started
Casey Labrack
Workspace
Fork
Published
advent of code 2020
By
Casey Labrack
Edited
Dec 5, 2020
advent of code 2020
Day 12
Day 11
Day 9
Day 8
Day 6
Day 5
Day 4
Day 3
Day 2
Day 1
Insert cell
Insert cell
solve
(
input
)
// part 1
Insert cell
solve
=
data
=>
data
.
split
(
"\n"
)
.
map
(
seatID
)
// all seatIDs
.
reduce
(
(
acc
,
inc
)
=>
inc
>
acc
?
inc
:
acc
,
0
)
// find largest
Insert cell
{
const
ids
=
input
.
split
(
"\n"
)
.
map
(
seatID
)
.
sort
(
)
let
missing
=
[
]
for
(
let
i
=
1
;
i
<
ids
.
length
-
2
;
i
++
)
{
if
(
ids
[
i
]
-
ids
[
i
-
1
]
>
1
)
missing
.
push
(
{
seatid
:
ids
[
i
]
,
index
:
i
}
)
}
return
missing
}
Insert cell
seatID
=
str
=>
row
(
str
)
*
8
+
col
(
str
)
Insert cell
row
=
str
=>
first7
(
str
)
.
split
(
""
)
.
reduce
(
(
acc
,
inc
)
=>
inc
==
"F"
?
[
acc
[
0
]
,
Math
.
floor
(
(
acc
[
1
]
-
acc
[
0
]
)
/
2
)
+
acc
[
0
]
]
:
// Front (lower end)
[
Math
.
ceil
(
(
acc
[
1
]
-
acc
[
0
]
)
/
2
)
+
acc
[
0
]
,
acc
[
1
]
]
,
// Back (upper end)
[
0
,
127
]
)
[
0
]
Insert cell
first7
=
str
=>
str
.
substring
(
0
,
7
)
Insert cell
col
=
str
=>
last3
(
str
)
.
split
(
""
)
.
reduce
(
(
acc
,
inc
)
=>
inc
==
"L"
?
[
acc
[
0
]
,
Math
.
floor
(
(
acc
[
1
]
-
acc
[
0
]
)
/
2
)
+
acc
[
0
]
]
:
// Front (lower end)
[
Math
.
ceil
(
(
acc
[
1
]
-
acc
[
0
]
)
/
2
)
+
acc
[
0
]
,
acc
[
1
]
]
,
// Back (upper end)
[
0
,
7
]
)
[
0
]
Insert cell
last3
=
str
=>
str
.
substring
(
7
)
Insert cell
Insert cell
otherexampleinputs
=
[
"BFFFBBFRRR"
,
"FFFBBBFRRR"
,
"BBFFBBFRLL"
]
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
solve
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
seatID
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
row
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
first7
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
col
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
last3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
exampleinput
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
otherexampleinputs
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
input
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML