Platform
Resources
Pricing
Sign in
Get started
Casey Labrack
Workspace
Fork
Published
advent of code 2019
By
Casey Labrack
Edited
Dec 10, 2019
Insert cell
Insert cell
Insert cell
sameDigitTwiceInARow
=
x
=>
{
let
result
=
false
const
str
=
x
.
toString
(
)
.
split
(
""
)
for
(
let
i
=
0
;
i
<
str
.
length
-
1
;
i
++
)
{
result
=
str
[
i
]
==
str
[
i
+
1
]
||
result
}
return
result
}
Insert cell
digitsNeverDecrease
=
x
=>
{
let
result
=
true
const
str
=
x
.
toString
(
)
.
split
(
""
)
for
(
let
i
=
0
;
i
<
str
.
length
-
1
;
i
++
)
{
result
=
str
[
i
]
<=
str
[
i
+
1
]
&&
result
}
return
result
}
Insert cell
possibles
=
x
=>
{
const
[
min
,
max
]
=
x
.
split
(
"-"
)
.
map
(
d
=>
parseInt
(
d
)
)
return
Array
.
from
(
{
length
:
max
-
min
+
1
}
,
(
_
,
i
)
=>
i
+
min
)
// range
.
filter
(
sameDigitTwiceInARow
)
.
filter
(
digitsNeverDecrease
)
}
Insert cell
solve1
=
x
=>
possibles
(
x
)
.
length
Insert cell
solve1
(
data
)
Insert cell
Insert cell
tests
=
[
"112233"
,
"123444"
,
"111122"
]
Insert cell
repeats
=
x
=>
x
.
match
(
/(\d)\1+/g
)
Insert cell
hasValidRepeat
=
x
=>
x
.
reduce
(
(
acc
,
inc
)
=>
inc
.
length
==
2
||
acc
,
false
)
Insert cell
tests
.
map
(
String
)
.
map
(
repeats
)
.
map
(
hasValidRepeat
)
Insert cell
solve2
=
range
=>
possibles
(
range
)
.
map
(
String
)
.
map
(
repeats
)
.
filter
(
hasValidRepeat
)
.
length
Insert cell
solve2
(
data
)
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
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
sameDigitTwiceInARow
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
digitsNeverDecrease
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
possibles
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
solve1
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
tests
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
repeats
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
hasValidRepeat
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
solve2
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
data
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML