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
Advent of code 2021
Day 1: Sonar Sweep
Day 2: Dive!
Day 3: Binary Diagnostic
Day 4: Giant Squid
Day 5: Hydrothermal Venture
Day 6: Lanternfish
Day 7: The Treachery of Whales
Day 8: Seven Segment Search
Day 9: Smoke Basin
Day 10: Syntax Scoring
Day 11: Dumbo Octopus
Day 12: Passage Pathing
Day 13: Transparent Origami
Day 14: Extended Polymerization
Day 15: Chiton
Day 16: Packet Decoder
Day 17: Trick Shot
Day 18: Snailfish
Day 19: Beacon Scanner
Day 20: Trench map
Day 21: Dirac dice
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