Platform
Resources
Pricing
Sign in
Get started
Leo Orpilla III
Workspace
Fork
Public
🎄 Advent of Code 2023
By
Leo Orpilla III
Edited
Dec 2, 2023
Fork of
Day N - Advent of Code
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function
parse
(
input
)
{
return
input
.
split
(
"\n"
)
.
map
(
(
game
)
=>
game
.
split
(
":"
)
[
1
]
.
split
(
";"
)
.
flatMap
(
(
bag
)
=>
bag
.
split
(
","
)
.
map
(
(
entry
)
=>
entry
.
trim
(
)
.
split
(
" "
)
)
.
map
(
(
[
count
,
name
]
)
=>
[
parseInt
(
count
)
,
name
]
)
)
)
;
}
Insert cell
Insert cell
function
isPossible
(
game
)
{
return
!
game
.
some
(
(
[
count
,
cube
]
)
=>
(
cube
===
"red"
&&
count
>
12
)
||
(
cube
===
"green"
&&
count
>
13
)
||
(
cube
===
"blue"
&&
count
>
14
)
)
;
}
Insert cell
Insert cell
function
part1
(
input
)
{
const
games
=
parse
(
input
)
;
return
_
.
sum
(
games
.
map
(
(
game
,
i
)
=>
(
isPossible
(
game
)
?
i
+
1
:
0
)
)
)
;
}
Insert cell
Insert cell
Insert cell
Insert cell
function
powerSet
(
game
)
{
const
groupedCubes
=
_
.
groupBy
(
game
,
(
d
)
=>
d
[
1
]
)
;
const
maxCubes
=
_
.
map
(
groupedCubes
,
(
cubes
)
=>
_
.
maxBy
(
cubes
,
0
)
[
0
]
)
;
return
maxCubes
.
reduce
(
(
a
,
b
)
=>
a
*
b
,
1
)
;
}
Insert cell
Insert cell
function
part2
(
input
)
{
const
games
=
parse
(
input
)
;
return
_
.
sum
(
games
.
map
(
powerSet
)
)
;
}
Insert cell
Insert cell
Insert cell
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
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
select
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
textarea
Edit
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
parse
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
isPossible
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
powerSet
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
Edit
Add comment
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
testInput
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
problemInput
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML