Platform
Resources
Pricing
Sign in
Get started
Philippe Rigovanov
math & informatics teacher
Workspace
Fork
Public
By
Philippe Rigovanov
Edited
Dec 1, 2023
Fork of
Advent of Code: 2016 Day 7
1
Insert cell
Insert cell
Insert cell
function
hypernets
(
ip
)
{
return
(
ip
.
match
(
/\[[^\]]*\]/g
)
||
[
]
)
.
join
(
" "
)
;
}
Insert cell
Insert cell
function
supernets
(
ip
)
{
return
ip
.
split
(
/\[[^\]]*\]/
)
.
join
(
" "
)
;
}
Insert cell
Insert cell
function
supportsTls
(
ip
)
{
const
hasAbba
=
(
str
)
=>
/(.)(?!\1)(.)\2\1/
.
test
(
str
)
;
return
hasAbba
(
supernets
(
ip
)
)
&&
!
hasAbba
(
hypernets
(
ip
)
)
;
}
Insert cell
function
part1
(
ips
)
{
return
ips
.
split
(
"\n"
)
.
filter
(
supportsTls
)
.
length
;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function
findABAs
(
str
)
{
const
abas
=
[
]
;
for
(
let
i
=
0
;
i
<
str
.
length
-
2
;
i
++
)
{
if
(
str
[
i
]
===
str
[
i
+
2
]
&&
str
[
i
]
!==
str
[
i
+
1
]
)
{
abas
.
push
(
str
.
slice
(
i
,
i
+
3
)
)
;
}
}
return
abas
;
}
Insert cell
Insert cell
function
supportsSsl
(
ip
)
{
const
abas
=
findABAs
(
supernets
(
ip
)
)
;
for
(
const
aba
of
abas
)
{
if
(
hypernets
(
ip
)
.
includes
(
aba
[
1
]
+
aba
[
0
]
+
aba
[
1
]
)
)
{
return
true
;
}
}
return
false
;
}
Insert cell
function
part2
(
input
)
{
return
input
.
split
(
"\n"
)
.
filter
(
supportsSsl
)
.
length
;
}
Insert cell
Insert cell
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
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
hypernets
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
supernets
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
supportsTls
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
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
findABAs
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
supportsSsl
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
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
Edit
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
puzzleInput
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML