Platform
Resources
Pricing
Sign in
Get started
Philippe Rigovanov
math & informatics teacher
Workspace
Fork
Public
By
Philippe Rigovanov
Edited
Dec 3, 2023
Fork of
Advent of Code 2023 - #1
Insert cell
Insert cell
Insert cell
d3
.
sum
(
input
.
split
(
"\n"
)
.
map
(
(
d
)
=>
[
...
d
]
.
find
(
(
c
)
=>
c
.
match
(
/[0-9]/
)
)
+
[
...
d
]
.
reverse
(
)
.
find
(
(
c
)
=>
c
.
match
(
/[0-9]/
)
)
)
)
Insert cell
Insert cell
d3
.
sum
(
input
.
split
(
"\n"
)
,
numm
)
Insert cell
numm
=
(
t
)
=>
value
(
digit
(
t
,
fwd
(
t
)
)
)
+
value
(
digit
(
t
,
bw
(
t
)
)
)
Insert cell
numm
(
"eightwo"
)
// for @visnup
Insert cell
fwd
=
(
(
string
)
=>
d3
.
range
(
string
.
length
)
.
find
(
(
i
)
=>
digit
(
string
,
i
)
)
)
Insert cell
bw
=
(
string
)
=>
d3
.
range
(
string
.
length
)
.
reverse
(
)
.
find
(
(
i
)
=>
digit
(
string
,
i
)
)
Insert cell
digits
=
[
"zero"
,
"one"
,
"two"
,
"three"
,
"four"
,
"five"
,
"six"
,
"seven"
,
"eight"
,
"nine"
,
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
]
Insert cell
digit
=
(
text
,
i
)
=>
digits
.
find
(
(
d
)
=>
text
.
slice
(
i
)
.
startsWith
(
d
)
)
Insert cell
function
value
(
d
)
{
return
String
(
digits
.
indexOf
(
d
)
%
10
)
;
}
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
numm
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
fwd
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
bw
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
digits
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
digit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
value
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
input
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML