Platform
Resources
Pricing
Sign in
Get started
Vincent Raveneau
CNRS Research Engineer at LIRMM, Montpellier, France.
Workspace
Fork
Published
Advent of code 2021
By
Vincent Raveneau
Edited
Dec 22, 2021
1
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
addedInput
.
getMagnitude
(
)
Insert cell
Insert cell
{
let
maxMagnitude
=
0
for
(
let
idx1
=
0
;
idx1
<
inputSnailNumbers
.
length
;
idx1
++
)
{
for
(
let
idx2
=
0
;
idx2
<
inputSnailNumbers
.
length
;
idx2
++
)
{
let
nbr1
=
new
Tree
(
txtToObject
(
inputSnailNumbers
[
idx1
]
.
toString
(
)
)
)
let
nbr2
=
new
Tree
(
txtToObject
(
inputSnailNumbers
[
idx2
]
.
toString
(
)
)
)
nbr1
.
add
(
nbr2
)
let
magnitude
=
nbr1
.
getMagnitude
(
)
if
(
magnitude
>
maxMagnitude
)
maxMagnitude
=
magnitude
}
}
return
maxMagnitude
}
Insert cell
Insert cell
Insert cell
Insert cell
function
txtToObject
(
txt
)
{
return
JSON
.
parse
(
txt
.
replace
(
/\[/g
,
"{\"left\":"
)
.
replace
(
/\]/g
,
"}"
)
.
replace
(
/,/g
,
", \"right\":"
)
)
}
Insert cell
inputSnailNumbers
=
input
.
map
(
txt
=>
new
Tree
(
txtToObject
(
txt
)
)
)
Insert cell
test
=
processSnailNumber
(
"[[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]]"
)
Insert cell
input
=
FileAttachment
(
"18_input.txt"
)
.
text
(
)
.
then
(
txt
=>
txt
.
trim
(
)
.
split
(
"\n"
)
)
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
addUpTo
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
addedInput
Edit
Add comment
Copy import
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Tree
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Node
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
txtToObject
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
inputSnailNumbers
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
test
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
input
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML