Platform
Resources
Pricing
Sign in
Get started
George Hotelling
Workspace
Fork
Published
Advent of Code 2019
By
George Hotelling
Edited
Dec 9, 2019
Insert cell
md
`# Advent of Code 2019 Day 8`
Insert cell
input
=
`2222220222222202222220210202222220222222220222222022222222222222220222222222222222002220022222222222021022022210022222222202222220121222222222222222202222220222222202222220211222222221222222222222222222222222222222222222222222222222002222222222222222020122222202222222222202222220122222222222222222202222221222222222222221210222222220222222221222222122222222222222220222222222222222112221022222222222021122022202022222222202222220120222222222222222222222221222222222222222202202222220222222220222202122222222222
22222022222222222202220222222222222222212202222220002222222221222222102122222222222222221222222122222220222222122121222222022222222122220222222222222222222122222222222212201222222222222221212102222220022222222220222222202222222222222222222222222222222221222022120221222222222222022022222222222222222222222222222222222212212222202222222222202222212222212222222220222222202222222222222222221222222122222220222122220122222222022222222122222202222222222222222222222222222212212222112222222222202202202220102222222220
22222211202222222222222222022222202222222122212202022222222212222202222222022222222222222222202222222222221220122202222222222220210221222121222222222222222210102222222222222222022222202222222122202212212022222202222202202222222222222222222222212222222222222220222220222222222021201212222222222222222222222220112222222222222222022202222222222122202212012022222222222212212222221222222222222222202222222222221220022220222222222222222220222001222222222222222202102222220222222222222222212222222022202222112222222212
22221221222222022222222222222222222222222222122102220222222222222121221022202122222222202222221110222222222222222202220222222222202220220220222222222222221220222202122222222222222222222222222222222202221022222222222121221122201222222222202222222120222222222222222222222222222222212220222221222222222222221221222212022222222222222220222222222222122012220122222222202020021022202122222222222222221012222222122222222202221220222222202222222200202222222222220221222202122222222222222220222222222222022202220022222222
20202212112222212222222222222222001222222202222222220222022122222222222122022122222222122222122022222222222222222222222122222222222222210222202221222220212102012220102222222222222222101122222212222222222222122222222221222022221020222222222222222022222222222222222222222122222222222202200222112222222221222222212220112222222220222222021222222212222222222222222222222222222122220221022222122222222222221202222222222222222022222222222202212222002221222221202022122222222222222220222222222222222212222222221222222022
22222122202212102022222212222202212222221222222222222222222222222222220220122010222122222221222210222201222222222222222222002222221222222222122202222222222122212212012122222222222222212222221222222222222222202222222222220221122102222022222022221222222222222222222022222022122222221222222222022202212222222122222202202102122212222222202222120222222222222222222222222222221221222022222122222121211200222212222222222222222200022222220222222222122202202222222022222222122212222212222212222222122222222222222222212222
22222222022102201222222222202020120022201222222222212222212112122222222222222212222222222222202222221221201222220222221220222222122222222222222220222222222222122212221022202222212122020122210020222222212222200020122222122222222222220222222222212220221202211212220222220221222212022222222222222220222222222222020100201022202222202222020122021120222222202222211111022222122222222212222220222222212221221202221202221222221222222222022222222222222221222222222222021011201122222222202121121222221220222222202222210221
02222212222222220222022122222222222222122222220222222222222122220202222222222222222222222222222222101022022221222220212212212210202022222220222220120102222202222222222222122222222220222222220021122222022222022222222202222222222222222122222222222212210020202220222220222102222221022022222202222222111012222212222222221222122022222221222022220022221222122222122022221222222222222222222222222222222202001222022221222222202122222210112122222201222221000112222212222222220222222122222221222122122221221222022222022222
22220222222222222222202222222222222200202000222022222220212220220201202222220222222221011222222222222222012212212222222022202212012012222212222212212222022222222222222220202222222222220210212111222122222221221222221010202222222022222122200222222222222222102212212222222022202202112022022212222212202222122222222222222222202222222222221211012102222222222221222221221112202222220222222221100222221222222222022212202222222022202202002122122202222202202222122222222222222220222222222222222210212001222122222122200210
22211122222222002222221001022222122222222221221222222222202222222220220202221222222222222222122222222222222020222222222222120210121222202222212220020122202222122222202222201102222222122222222211221220222222222220222201211201220222022221222212222222222222222020222222222222022100202222202222222222221222222220222222012222221121122222122222222201221220222222222222222210200211222222220221222222022222222222222221222222222222022111112122212022222222020022221121022222222222221210222222122222222212222121222222202221
22022020022122122222222222222212222222222222222122222222222222002102202222202222212012012222022222222210222221012012222202222222221122002022222221222122121220220222022202022022222212222222222222222122220222222202011000212220222221202112202202212212222200222222111002222202222222220022012222222220222122122222121022022202122222222202222222222222222122221222202202201220212220222221222202202212202022222221222221102022222212222222221022202222222221222122122220222222122212122122221212222222222222222122220222222212
10022020222221222020200222220001220222221122222121221222220222222222222222212222222222212222122112212222221222202222222222222222222221212222222222222212210111222221222022200202220100221222220122222222022222221222222222212201222221222222222202222112222212222212202222022222222222222222222222022220222202001211222021222221201211221211211222220222222020020222201222222222222201222220222022202202202102222222221222222222021222222222222222202222122220222202100001222122222022211202222000200222220022222111111222210222
22222201220220222222202220222200210211222222021221222202122222222222222222222202222122220101020022202022212121221222001122122221122222201020222221222222222201220120222222212221222212211211222222222221222212222222222222222220222202222122221220020222222222202022020022112120022222112222222002222220022222222221221021222022112211221221210212221222221221222202022222222222222221222222222022222112022122212122212121021222012022122021011222220120122221122222222201221220222222202201220210212210220222121222222202122222
22222222211022222222222022112211102121202221222112102212202222202111222220211022222102222222220122212022212212222122222222120122022222022022221202222222222222222222221222202102220202212112202221222122012200222212202201022222020012222112222222220022112122212210220222221120220122022222022022201212222222022222210122222222202122021020012222212220202112002211002202222202122020211222222112222222222220122022222212221222220022021022022202122222220210222222122222200122222222212002002000102020212222222222102211112102
20202222222020211222200222022222202202222020220222022212122102122212221222222221120022222222222221202222222221222221200211200122202222200212221010201220212102212211111222210222022222122210202221220122012222002222102202220202202220020022222212222220102222122201210220210111202121202021222200222211210222211222212212201222200222222222222111222220221122202212022012122202220212212221120222222202222222022222122210201221120022220222212022220222220020211221201120202110112222202222022222122020222222220022102212112012
12222222121222222202102222220222222121222212222122020020101220122222202122022122221120022020012122200002122221022202222201222121222122112210222211210221022222120222222222202222220222222211222202222121222102022220122222212021001022212022122020012022212110022222122202022222220020212122212220221202211221122222022220220202122222220222222200222212222122020211222021102020202222201222011220222120211222222202222220222202222211220220202022012212220201200210020222021222201002112222221222222011222202220220120112202221
12212120202211122210022002212210202120122112222112221202222021022021222222220222221221120202122202222020112220222222222222202022222222022102121002122101222222212110112201102002212021222120200022222202222222221222022222222212221022221022222022222222022122102211221220222222202222220222212022101012012202220021212021022220012112202002102121000022222112221222220020022222202211221222020021221212222222222220222222222220022222210122222222012212122000002202212221222111022221022012202022122020121222222222200202221022
20202021221222222222122112121212121202212111222222022212222222222222022212202221112210210020112020200120221020211220212122212102222222222221021212112110212220222222022212002022101222122212212122010222122022222222002222022201201211221121202122102221211012222121210222212100202120110222222221020202212112212022220222012212102022120202022202202120200022222022222222022222222221200222110212202020012121222201221211200222200012212102021222222222222222122012222120220122022212102002022202221202202010210022222112222222
21222222222221020000012221122202202121211022112021022120021022221102022220022222021220222220212122022210222220211222022202020221211212002202220222222020222202220221220220010222112002212120201022001021022021111102201002122221122002120211222122222222002221221220221202022202120202212020102202211202222012222222222021120211200021012011212020101122212021022122201122220220222222122022222220201022202022202221222222201201120212120202220012222210212212222212222222220021121111011222022220212021110122020222122121010201
20211202222012220202221220222121202210222022122221222202221202021022122120221221222222202122220222002222112212112222221122222111122222212212222102022020120122222112201202121122222022212211220222221121120212220212122121011120220221222222212122221222002022220220112222202020212102112200212202202020001122122222222222212202022020112122212200222022121122220012222212121022202110221220020222222222222222122002222222202000201222202210112211122122222002001221210122222002200212020021022122212211220222220221220202100222
02112111102222212022022222022222122220211221220010201122102020202021222012202222222211202222110222210221221202102222112220221222012212102022001202020222022010000222222222222221112222222221201201021122212222022220210221222010220221220111122200012222222222122202002211222220222122212212102002222201022222002002100122201212222221202222122210211200101111221221122022221112201111221222200010212211001222221221221222102221102020222022102222112122121012020212202202102022221212022222122222122211202222012120222121002122
22211022002121122121211022202222022220022022020211201110212022022222222212200212220102021202201022212212110212222202222002220020021121200222222001202222121120222220122122112000202110122220222222122201210012222022222221222211222221200122122202202211022222101222122011222112222122020200101221122202212020212021102220022121200220210100022220122022122201211100222122012200220212211211001222122210221102112201021222222120222022201020221010000021222000222122220122101021222221202101202110122222022012122220210222212222
12221122022222021212022202122120222200222101121222201122200222022012111121222121212120222022212200222022212112012122100112222022210022220222102222222212220222220022221012202212222021111021220121221202221122222220002002100011002102202022002112202010202102202121201021112112222222211002121020102020202201220122120121122121212212121122222102220120120222222222211211001012012010212012201121212220202101222202222121220221221012222012222202220122020120202201222122222021120010000202122020001001220220121222210222200200
21021221020101210201012021210112202011212222210002012111200222220221110212122001012122221022002202002112010012222202202121110122021002022222112221120120120221200100212212102121210021210220212220220220112120012222202222110222002120222121222022122202202222122210021202012020111222000222022222112222022210102201221110210111222001211120200001202221210110202122202222022220020222222111222021221222212212112222100222021202122110222022101222021222202221221220021211122101220211002122211202202212202222221022102211022222
12122022220212212100202222002222220222200201010002020211210211002222022222022211222102100002021210200221100010222121001120110022122121120220212102122202122020120200210211212122222202222200211200212112221211212102202201011212122202222012120120122102100122010010201021200122212120122222210001200010222200222121021202011201222022212201220220211212002002120120220021002201112222222202222102100211020211100020111012222020200221010122122022201022200102022202022122011222201222210122112222222220210220011002222101211220
11221122122212211102211212011102020102122012022022012102112111112122022110111121012102222102201020120012012220022211221022121121122121212212022122110112222022120112211012220200210202202011012021010021202210112220002002102121212121212222222022220202221102120022222200222222221222221102011212220120220112222021222112202212202220120012102011222102220222022210112021102202012120010020022222222202202110221110021021102101222222022222220022102212001220122001220121220102212222210211100022021011012120210221022112012212
21200221202001112011000222011222201202012211102100111122022222001212122212221212102021210022202102221220220221120211211211220100212212122220222110212100211201202211002111021222200220110012012221022022000122012202121212021021220202122002011222021002100220112222120022022202102212211100222200202201211100222200202112122221200222102221021122022010222210120022112202101012112102021222222212200122011212112222222220220101210210010001221022122211201022212121212202220112002120102222201220212222020212202021012222012222
10020211100012120220201022002202202221122220122122020101120221210120111021210221110121211021002221220121222000022200222102010202222100211211202201220202122202012022121110212121212220210222022210022002111022220102100220102022220122120221110120220021220122212212122221222201022220101002221110112200221200112222010112022110202000012222221202222012222122022201222000002220000101022021022121001222222222121011202120222210222101200202110200222022222210222220002212222202220211221111122212220211122221122202021200020000
01002220211200020120212021212001022011221020221122222212210102121100102220100022220022212000222121212202011010220121221211220102222012220202220002000010222010021001202121222110212200112000120122111202200112200210221011102222201202220022121110022002010222102210212120222212121102012222200201020022212000212101011122222022022010002021022002212221012022211202200202220001202221112121222022002022121221120210220011002121220002022002001022201210221222021121202221221100022120002001222010112212010121020202201022202110
021100020200012021110100000212101100120000221211202121102220002001020111011021022201112011000011201010111000210102000112120100201110001110112221020202000
`
Insert cell
stream
=
input
.
split
(
''
)
.
map
(
n
=>
parseInt
(
n
)
)
Insert cell
width
=
25
Insert cell
height
=
6
Insert cell
layers
=
[
]
;
Insert cell
{
for
(
let
i
=
0
;
i
<
input
.
length
;
i
+=
(
width
*
height
)
)
{
const
layer
=
stream
.
slice
(
i
,
i
+
(
width
*
height
)
)
;
layers
.
push
(
layer
)
;
}
return
layers
;
}
Insert cell
count
=
(
num
,
layer
)
=>
{
let
found
=
0
;
for
(
let
i
=
0
;
i
<
layer
.
length
;
i
++
)
{
if
(
layer
[
i
]
==
num
)
found
++
;
}
return
found
;
}
Insert cell
count
(
0
,
layers
[
0
]
)
Insert cell
checkLayer
=
layers
.
reduce
(
(
a
,
b
)
=>
(
count
(
0
,
a
)
<
count
(
0
,
b
)
?
a
:
b
)
)
Insert cell
{
return
count
(
1
,
checkLayer
)
*
count
(
2
,
checkLayer
)
}
Insert cell
stack
=
(
front
,
back
)
=>
{
const
result
=
[
]
;
for
(
let
i
=
0
;
i
<
front
.
length
;
i
++
)
{
result
[
i
]
=
(
front
[
i
]
!=
2
)
?
front
[
i
]
:
back
[
i
]
;
}
return
result
;
}
Insert cell
stacked
=
layers
.
reduce
(
stack
)
Insert cell
{
let
output
=
''
;
for
(
let
i
=
0
;
i
<
height
;
i
++
)
{
for
(
let
j
=
0
;
j
<
width
;
j
++
)
{
output
+=
(
stacked
[
(
i
*
width
)
+
j
]
==
1
)
?
'#'
:
' '
;
}
output
+=
"\n "
;
}
return
output
;
}
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
input
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
stream
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
width
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
height
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
layers
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
count
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
checkLayer
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
stack
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
stacked
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML