Platform
Resources
Pricing
Sign in
Get started
Visnu Pitiyanuvath
Workspace
Fork
Public
Advent of Code 2022
By
Visnu Pitiyanuvath
Edited
Dec 2, 2022
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
part2
=
d3
.
sum
(
rounds
.
map
(
score2
)
)
Insert cell
score2
=
(
[
other
,
outcome
]
)
=>
{
other
=
other
.
charCodeAt
(
0
)
-
"A"
.
charCodeAt
(
0
)
;
outcome
=
outcomes
[
outcome
]
;
const
you
=
{
6
:
(
other
+
1
)
%
3
,
3
:
other
,
0
:
(
other
-
1
+
3
)
%
3
}
[
outcome
]
;
return
you
+
1
+
outcome
;
}
Insert cell
Insert cell
outcomes
=
(
{
X
:
0
,
Y
:
3
,
Z
:
6
}
)
Insert cell
part1
=
d3
.
sum
(
rounds
.
map
(
score
)
)
Insert cell
rounds
=
data
.
trim
(
)
.
split
(
"\n"
)
.
map
(
r
=>
r
.
split
(
" "
)
)
Insert cell
score
=
(
[
other
,
you
]
)
=>
{
other
=
other
.
charCodeAt
(
0
)
-
"A"
.
charCodeAt
(
0
)
;
you
=
you
.
charCodeAt
(
0
)
-
"X"
.
charCodeAt
(
0
)
;
const
win
=
you
===
(
other
+
1
)
%
3
;
return
you
+
1
+
(
win
?
6
:
you
===
other
?
3
:
0
)
;
}
Insert cell
sample
=
`
A Y
B X
C Z
`
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
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
score2
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
outcomes
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
part1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
rounds
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
score
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
sample
Unpin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
data
Edit
Pin
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
JavaScript
Markdown
HTML
JavaScript
Markdown
HTML
JavaScript
Markdown
HTML
JavaScript
Markdown
HTML