Platform
Resources
Pricing
Sign in
Get started
Visnu Pitiyanuvath
Workspace
Fork
Public
Advent of Code 2023
By
Visnu Pitiyanuvath
Edited
Dec 4, 2023
1 fork
1 star
Insert cell
Insert cell
cards
=
input
.
trim
(
)
.
split
(
"\n"
)
.
map
(
(
line
,
i
)
=>
{
const
[
,
winning
,
have
]
=
line
.
split
(
/[:|]/
)
.
map
(
(
d
)
=>
d
&&
new
Set
(
d
.
trim
(
)
.
split
(
/\s+/
)
.
map
(
Number
)
)
)
;
return
{
i
,
winning
,
have
,
won
:
d3
.
intersection
(
winning
,
have
)
.
size
}
;
}
)
Insert cell
Insert cell
part1
=
d3
.
sum
(
cards
,
(
{
won
}
)
=>
Math
.
sign
(
won
)
<<
(
won
-
1
)
)
Insert cell
Insert cell
part2
=
{
const
q
=
[
...
cards
]
;
let
seen
=
0
;
while
(
q
.
length
)
{
const
{
i
,
won
}
=
q
.
shift
(
)
;
for
(
let
j
=
1
;
j
<=
won
;
j
++
)
q
.
push
(
cards
[
i
+
j
]
)
;
seen
++
;
}
return
seen
;
}
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
cards
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
part1
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
part2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sample
Edit
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