Platform
Resources
Pricing
Sign in
Get started
Visnu Pitiyanuvath
Workspace
Fork
Published
Advent of Code 2021
By
Visnu Pitiyanuvath
Edited
Dec 9, 2021
3 stars
Insert cell
Insert cell
Insert cell
generations
=
{
const
generations
=
[
]
;
for
(
const
n
of
run
(
data
,
256
)
)
{
generations
.
push
(
n
)
;
yield
generations
;
}
}
Insert cell
part2
=
run
(
data
,
256
)
Insert cell
part1
=
run
(
data
,
80
)
Insert cell
function
*
run
(
data
,
n
)
{
while
(
n
--
)
{
data
=
step
(
data
)
;
yield
_
.
sum
(
Object
.
values
(
data
)
)
;
}
}
Insert cell
step
=
(
fishes
)
=>
{
const
next
=
{
}
;
for
(
const
[
n
,
count
]
of
Object
.
entries
(
fishes
)
)
{
if
(
n
>
0
)
{
next
[
n
-
1
]
=
(
next
[
n
-
1
]
||
0
)
+
count
;
}
else
{
next
[
6
]
=
(
next
[
6
]
||
0
)
+
count
;
next
[
8
]
=
(
next
[
8
]
||
0
)
+
count
;
}
}
return
next
;
}
Insert cell
data
=
_
.
countBy
(
(
which
===
"test"
?
test
:
input
)
.
trim
(
)
.
split
(
","
)
)
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
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
generations
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
part1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
run
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
step
Add comment
Copy import
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
which
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
test
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