Day 10
authorNeil Smith <neil.git@njae.me.uk>
Tue, 11 Dec 2018 18:14:14 +0000 (18:14 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Tue, 11 Dec 2018 18:14:14 +0000 (18:14 +0000)
data/advent10-small.txt [new file with mode: 0644]
data/advent10.txt [new file with mode: 0644]
problems/day10.html [new file with mode: 0644]
src/advent10/advent10-iterate-zip.hs [new file with mode: 0644]
src/advent10/advent10.hs [new file with mode: 0644]

diff --git a/data/advent10-small.txt b/data/advent10-small.txt
new file mode 100644 (file)
index 0000000..e499c03
--- /dev/null
@@ -0,0 +1,31 @@
+position=< 9,  1> velocity=< 0,  2>
+position=< 7,  0> velocity=<-1,  0>
+position=< 3, -2> velocity=<-1,  1>
+position=< 6, 10> velocity=<-2, -1>
+position=< 2, -4> velocity=< 2,  2>
+position=<-6, 10> velocity=< 2, -2>
+position=< 1,  8> velocity=< 1, -1>
+position=< 1,  7> velocity=< 1,  0>
+position=<-3, 11> velocity=< 1, -2>
+position=< 7,  6> velocity=<-1, -1>
+position=<-2,  3> velocity=< 1,  0>
+position=<-4,  3> velocity=< 2,  0>
+position=<10, -3> velocity=<-1,  1>
+position=< 5, 11> velocity=< 1, -2>
+position=< 4,  7> velocity=< 0, -1>
+position=< 8, -2> velocity=< 0,  1>
+position=<15,  0> velocity=<-2,  0>
+position=< 1,  6> velocity=< 1,  0>
+position=< 8,  9> velocity=< 0, -1>
+position=< 3,  3> velocity=<-1,  1>
+position=< 0,  5> velocity=< 0, -1>
+position=<-2,  2> velocity=< 2,  0>
+position=< 5, -2> velocity=< 1,  2>
+position=< 1,  4> velocity=< 2,  1>
+position=<-2,  7> velocity=< 2, -2>
+position=< 3,  6> velocity=<-1, -1>
+position=< 5,  0> velocity=< 1,  0>
+position=<-6,  0> velocity=< 2,  0>
+position=< 5,  9> velocity=< 1, -2>
+position=<14,  7> velocity=<-2,  0>
+position=<-3,  6> velocity=< 2, -1>
diff --git a/data/advent10.txt b/data/advent10.txt
new file mode 100644 (file)
index 0000000..63f5ca5
--- /dev/null
@@ -0,0 +1,394 @@
+position=< 52672,  52690> velocity=<-5, -5>
+position=<-20892,  10646> velocity=< 2, -1>
+position=<-10378, -52423> velocity=< 1,  5>
+position=< 21199, -20892> velocity=<-2,  2>
+position=< 21187,  42176> velocity=<-2, -4>
+position=<-31392,  10644> velocity=< 3, -1>
+position=< 21152,  31665> velocity=<-2, -3>
+position=<-20880, -41905> velocity=< 2,  4>
+position=< 21200, -10373> velocity=<-2,  1>
+position=< 31652,  42178> velocity=<-3, -4>
+position=<-20873,  31671> velocity=< 2, -3>
+position=< 52717,  42181> velocity=<-5, -4>
+position=<-10350,  10650> velocity=< 1, -1>
+position=< 31691, -10372> velocity=<-3,  1>
+position=<-52390,  21157> velocity=< 5, -2>
+position=<-10354,  52690> velocity=< 1, -5>
+position=< 52696, -41906> velocity=<-5,  4>
+position=<-10354,  42182> velocity=< 1, -4>
+position=<-20879, -20883> velocity=< 2,  2>
+position=<-52382,  52688> velocity=< 5, -5>
+position=<-41906, -20891> velocity=< 4,  2>
+position=<-10394, -31401> velocity=< 1,  3>
+position=<-20873,  31670> velocity=< 2, -3>
+position=< 52700,  31663> velocity=<-5, -3>
+position=<-52414, -20888> velocity=< 5,  2>
+position=<-52438,  42182> velocity=< 5, -4>
+position=< 42205,  10641> velocity=<-4, -1>
+position=< 42169,  10646> velocity=<-4, -1>
+position=<-52406,  10647> velocity=< 5, -1>
+position=< 42178,  52689> velocity=<-4, -5>
+position=< 52725, -31399> velocity=<-5,  3>
+position=<-31372, -41905> velocity=< 3,  4>
+position=< 10657,  31670> velocity=<-1, -3>
+position=<-31363, -20890> velocity=< 3,  2>
+position=<-10352,  52689> velocity=< 1, -5>
+position=<-41884,  42178> velocity=< 4, -4>
+position=< 52720, -20883> velocity=<-5,  2>
+position=< 21143, -31399> velocity=<-2,  3>
+position=<-31381,  52685> velocity=< 3, -5>
+position=<-20863, -52425> velocity=< 2,  5>
+position=<-20885,  21158> velocity=< 2, -2>
+position=<-31376,  52687> velocity=< 3, -5>
+position=<-20873, -31399> velocity=< 2,  3>
+position=< 21155,  10648> velocity=<-2, -1>
+position=< 42214,  52690> velocity=<-4, -5>
+position=< 10636, -41906> velocity=<-1,  4>
+position=<-10365, -52416> velocity=< 1,  5>
+position=< 42161,  21154> velocity=<-4, -2>
+position=< 10644, -10380> velocity=<-1,  1>
+position=<-41867,  10641> velocity=< 4, -1>
+position=<-31390,  10650> velocity=< 3, -1>
+position=< 31698, -20884> velocity=<-3,  2>
+position=< 52709, -31402> velocity=<-5,  3>
+position=< 10630, -52425> velocity=<-1,  5>
+position=< 42186,  31663> velocity=<-4, -3>
+position=<-41887, -31399> velocity=< 4,  3>
+position=< 42217, -52425> velocity=<-4,  5>
+position=<-52386, -52421> velocity=< 5,  5>
+position=<-20892,  42182> velocity=< 2, -4>
+position=< 10657, -10376> velocity=<-1,  1>
+position=<-20892, -41908> velocity=< 2,  4>
+position=< 21168,  42175> velocity=<-2, -4>
+position=<-31403, -20883> velocity=< 3,  2>
+position=< 31695,  10649> velocity=<-3, -1>
+position=< 31687,  31664> velocity=<-3, -3>
+position=<-41914, -10380> velocity=< 4,  1>
+position=<-10351, -20883> velocity=< 1,  2>
+position=< 10678,  31667> velocity=<-1, -3>
+position=< 52701, -31395> velocity=<-5,  3>
+position=< 31686, -41914> velocity=<-3,  4>
+position=<-52398, -31399> velocity=< 5,  3>
+position=<-41887,  10642> velocity=< 4, -1>
+position=< 42209, -52419> velocity=<-4,  5>
+position=<-52422,  52693> velocity=< 5, -5>
+position=<-20881,  52690> velocity=< 2, -5>
+position=< 31671, -31400> velocity=<-3,  3>
+position=<-41924, -41910> velocity=< 4,  4>
+position=<-20852,  52689> velocity=< 2, -5>
+position=< 42201, -52422> velocity=<-4,  5>
+position=< 31691,  21161> velocity=<-3, -2>
+position=<-41870, -31399> velocity=< 4,  3>
+position=<-20889, -52423> velocity=< 2,  5>
+position=< 42169,  21153> velocity=<-4, -2>
+position=< 52672, -52420> velocity=<-5,  5>
+position=< 52691, -10381> velocity=<-5,  1>
+position=<-41882,  52690> velocity=< 4, -5>
+position=<-31403,  10649> velocity=< 3, -1>
+position=<-41871, -20885> velocity=< 4,  2>
+position=<-52393,  21158> velocity=< 5, -2>
+position=<-41867,  31667> velocity=< 4, -3>
+position=< 31686, -52421> velocity=<-3,  5>
+position=<-52385, -20887> velocity=< 5,  2>
+position=<-31412, -52425> velocity=< 3,  5>
+position=<-31395,  10643> velocity=< 3, -1>
+position=< 52706,  52685> velocity=<-5, -5>
+position=< 31670,  10645> velocity=<-3, -1>
+position=<-10374, -31397> velocity=< 1,  3>
+position=<-41922, -31403> velocity=< 4,  3>
+position=<-20862, -41905> velocity=< 2,  4>
+position=< 52672,  21160> velocity=<-5, -2>
+position=< 31693, -20883> velocity=<-3,  2>
+position=<-20889, -10375> velocity=< 2,  1>
+position=<-31360,  10642> velocity=< 3, -1>
+position=< 10662,  21156> velocity=<-1, -2>
+position=< 21158, -10377> velocity=<-2,  1>
+position=<-31384,  52691> velocity=< 3, -5>
+position=< 10684,  10642> velocity=<-1, -1>
+position=<-20846, -31399> velocity=< 2,  3>
+position=<-52382, -20885> velocity=< 5,  2>
+position=< 31710, -41908> velocity=<-3,  4>
+position=<-10349, -20890> velocity=< 1,  2>
+position=< 52672,  10647> velocity=<-5, -1>
+position=< 10644, -10380> velocity=<-1,  1>
+position=<-41882,  52686> velocity=< 4, -5>
+position=<-31356,  31670> velocity=< 3, -3>
+position=<-10346, -20885> velocity=< 1,  2>
+position=<-31384,  42183> velocity=< 3, -4>
+position=<-41895, -52416> velocity=< 4,  5>
+position=< 52683,  10647> velocity=<-5, -1>
+position=<-10375,  21157> velocity=< 1, -2>
+position=< 42205,  42174> velocity=<-4, -4>
+position=<-20889, -41905> velocity=< 2,  4>
+position=< 10636, -52418> velocity=<-1,  5>
+position=<-20901, -52421> velocity=< 2,  5>
+position=< 10681, -10373> velocity=<-1,  1>
+position=<-20889, -20888> velocity=< 2,  2>
+position=<-31387, -20891> velocity=< 3,  2>
+position=<-31371,  10646> velocity=< 3, -1>
+position=<-41879, -10372> velocity=< 4,  1>
+position=< 31671,  31665> velocity=<-3, -3>
+position=< 10689, -20883> velocity=<-1,  2>
+position=< 10641,  52691> velocity=<-1, -5>
+position=<-41874,  10643> velocity=< 4, -1>
+position=<-52405,  10645> velocity=< 5, -1>
+position=<-20852,  10641> velocity=< 2, -1>
+position=<-41914, -20891> velocity=< 4,  2>
+position=< 52699,  42183> velocity=<-5, -4>
+position=< 10630, -10381> velocity=<-1,  1>
+position=< 21147, -31400> velocity=<-2,  3>
+position=< 42222,  52693> velocity=<-4, -5>
+position=< 31695, -41913> velocity=<-3,  4>
+position=< 31706,  21161> velocity=<-3, -2>
+position=<-31363,  31665> velocity=< 3, -3>
+position=< 42193, -41914> velocity=<-4,  4>
+position=< 52672,  31670> velocity=<-5, -3>
+position=<-10384, -20889> velocity=< 1,  2>
+position=< 10684,  21156> velocity=<-1, -2>
+position=<-10341, -52421> velocity=< 1,  5>
+position=<-41876,  21156> velocity=< 4, -2>
+position=< 52728,  42182> velocity=<-5, -4>
+position=< 31677, -41909> velocity=<-3,  4>
+position=<-31395,  52693> velocity=< 3, -5>
+position=< 52689,  10641> velocity=<-5, -1>
+position=<-31399,  10641> velocity=< 3, -1>
+position=< 52717,  21155> velocity=<-5, -2>
+position=<-52398, -10375> velocity=< 5,  1>
+position=<-10375,  10641> velocity=< 1, -1>
+position=< 42161,  21155> velocity=<-4, -2>
+position=< 21139, -31402> velocity=<-2,  3>
+position=<-52425, -41905> velocity=< 5,  4>
+position=<-52406, -41911> velocity=< 5,  4>
+position=<-31389,  21157> velocity=< 3, -2>
+position=<-31388,  21157> velocity=< 3, -2>
+position=<-52425, -20885> velocity=< 5,  2>
+position=<-10394, -10372> velocity=< 1,  1>
+position=<-31384, -20891> velocity=< 3,  2>
+position=< 42206,  31665> velocity=<-4, -3>
+position=<-52385, -31398> velocity=< 5,  3>
+position=<-10341, -31400> velocity=< 1,  3>
+position=<-10386, -52423> velocity=< 1,  5>
+position=<-10346,  52690> velocity=< 1, -5>
+position=< 21164, -20883> velocity=<-2,  2>
+position=< 42177,  10645> velocity=<-4, -1>
+position=< 52725,  10644> velocity=<-5, -1>
+position=< 42217,  52685> velocity=<-4, -5>
+position=< 31650, -41911> velocity=<-3,  4>
+position=<-31379, -41912> velocity=< 3,  4>
+position=<-41887,  42181> velocity=< 4, -4>
+position=<-52422, -31396> velocity=< 5,  3>
+position=<-31376, -20889> velocity=< 3,  2>
+position=<-41878,  21156> velocity=< 4, -2>
+position=< 10684,  31669> velocity=<-1, -3>
+position=< 31677, -41905> velocity=<-3,  4>
+position=<-31376, -41905> velocity=< 3,  4>
+position=<-52427, -10376> velocity=< 5,  1>
+position=< 21142,  42174> velocity=<-2, -4>
+position=<-20863, -52421> velocity=< 2,  5>
+position=<-52409, -41908> velocity=< 5,  4>
+position=< 21192,  21158> velocity=<-2, -2>
+position=<-41895, -31400> velocity=< 4,  3>
+position=< 52731,  52685> velocity=<-5, -5>
+position=<-52398,  10646> velocity=< 5, -1>
+position=<-31408, -20883> velocity=< 3,  2>
+position=< 21197,  31667> velocity=<-2, -3>
+position=<-31389,  52685> velocity=< 3, -5>
+position=<-41874,  42177> velocity=< 4, -4>
+position=<-52382,  31664> velocity=< 5, -3>
+position=<-52385, -31396> velocity=< 5,  3>
+position=< 42181, -31399> velocity=<-4,  3>
+position=<-20904,  10645> velocity=< 2, -1>
+position=<-10370,  42176> velocity=< 1, -4>
+position=<-52437, -31403> velocity=< 5,  3>
+position=< 31659, -31402> velocity=<-3,  3>
+position=< 10656, -41906> velocity=<-1,  4>
+position=<-41914,  42179> velocity=< 4, -4>
+position=<-20865,  21155> velocity=< 2, -2>
+position=<-10374, -31396> velocity=< 1,  3>
+position=<-20870,  42178> velocity=< 2, -4>
+position=< 21195,  31670> velocity=<-2, -3>
+position=< 21139, -31401> velocity=<-2,  3>
+position=<-31375, -31399> velocity=< 3,  3>
+position=< 42174, -41905> velocity=<-4,  4>
+position=< 31687,  31666> velocity=<-3, -3>
+position=<-31375, -10372> velocity=< 3,  1>
+position=<-10333, -52416> velocity=< 1,  5>
+position=< 21167,  52693> velocity=<-2, -5>
+position=< 42185,  52686> velocity=<-4, -5>
+position=<-10366,  52685> velocity=< 1, -5>
+position=< 42185, -10373> velocity=<-4,  1>
+position=< 52691, -52425> velocity=<-5,  5>
+position=<-41887,  52692> velocity=< 4, -5>
+position=< 31663,  31666> velocity=<-3, -3>
+position=< 42201,  31665> velocity=<-4, -3>
+position=<-41900,  42174> velocity=< 4, -4>
+position=< 31710,  42181> velocity=<-3, -4>
+position=<-52382, -20890> velocity=< 5,  2>
+position=< 42214, -41914> velocity=<-4,  4>
+position=< 10647, -10377> velocity=<-1,  1>
+position=< 31703, -20883> velocity=<-3,  2>
+position=< 31690, -20883> velocity=<-3,  2>
+position=< 10644, -20891> velocity=<-1,  2>
+position=< 21152,  52691> velocity=<-2, -5>
+position=<-20873,  10648> velocity=< 2, -1>
+position=<-31408, -52423> velocity=< 3,  5>
+position=< 31658, -41910> velocity=<-3,  4>
+position=<-10337, -41910> velocity=< 1,  4>
+position=< 21196, -10381> velocity=<-2,  1>
+position=< 42205, -10381> velocity=<-4,  1>
+position=<-10383,  52691> velocity=< 1, -5>
+position=<-10362,  52688> velocity=< 1, -5>
+position=<-52380, -41914> velocity=< 5,  4>
+position=< 52704,  31665> velocity=<-5, -3>
+position=< 52700, -31398> velocity=<-5,  3>
+position=< 52714,  10650> velocity=<-5, -1>
+position=< 42201, -52417> velocity=<-4,  5>
+position=<-20849,  21161> velocity=< 2, -2>
+position=<-20902,  42174> velocity=< 2, -4>
+position=< 31692, -41905> velocity=<-3,  4>
+position=< 10631, -20888> velocity=<-1,  2>
+position=< 42197,  10641> velocity=<-4, -1>
+position=<-10351,  42174> velocity=< 1, -4>
+position=< 10677, -20888> velocity=<-1,  2>
+position=< 31701,  10645> velocity=<-3, -1>
+position=<-31400,  31670> velocity=< 3, -3>
+position=< 21181,  21152> velocity=<-2, -2>
+position=< 10673,  21154> velocity=<-1, -2>
+position=< 52733, -10372> velocity=<-5,  1>
+position=< 10644, -41908> velocity=<-1,  4>
+position=< 42190,  10650> velocity=<-4, -1>
+position=<-20905,  52688> velocity=< 2, -5>
+position=<-10362, -10376> velocity=< 1,  1>
+position=< 31711,  21155> velocity=<-3, -2>
+position=< 10652,  52692> velocity=<-1, -5>
+position=<-41891, -31399> velocity=< 4,  3>
+position=< 21171, -41908> velocity=<-2,  4>
+position=< 31682, -10377> velocity=<-3,  1>
+position=< 52705,  42174> velocity=<-5, -4>
+position=< 52681, -41913> velocity=<-5,  4>
+position=< 42164, -41914> velocity=<-4,  4>
+position=<-10346, -31397> velocity=< 1,  3>
+position=<-31363,  42175> velocity=< 3, -4>
+position=< 42189,  10641> velocity=<-4, -1>
+position=<-20892,  42181> velocity=< 2, -4>
+position=< 21155, -10381> velocity=<-2,  1>
+position=< 10636, -52420> velocity=<-1,  5>
+position=<-41871,  52693> velocity=< 4, -5>
+position=< 42212,  42178> velocity=<-4, -4>
+position=< 31707,  42174> velocity=<-3, -4>
+position=< 52728,  31668> velocity=<-5, -3>
+position=< 31703, -20886> velocity=<-3,  2>
+position=<-52438, -10375> velocity=< 5,  1>
+position=<-20892,  21152> velocity=< 2, -2>
+position=<-31384, -41913> velocity=< 3,  4>
+position=< 52677, -52425> velocity=<-5,  5>
+position=<-52438,  31668> velocity=< 5, -3>
+position=<-20885,  52685> velocity=< 2, -5>
+position=<-31384, -41914> velocity=< 3,  4>
+position=< 31698, -10381> velocity=<-3,  1>
+position=<-52398, -10373> velocity=< 5,  1>
+position=< 31709, -10381> velocity=<-3,  1>
+position=< 10685, -31399> velocity=<-1,  3>
+position=<-41868, -10381> velocity=< 4,  1>
+position=< 52688, -52417> velocity=<-5,  5>
+position=< 10669, -31399> velocity=<-1,  3>
+position=< 10628, -52424> velocity=<-1,  5>
+position=< 31698, -31397> velocity=<-3,  3>
+position=<-52379, -10376> velocity=< 5,  1>
+position=< 21187,  52687> velocity=<-2, -5>
+position=<-41914,  10649> velocity=< 4, -1>
+position=< 42201,  10648> velocity=<-4, -1>
+position=<-41866, -31402> velocity=< 4,  3>
+position=< 31650,  31663> velocity=<-3, -3>
+position=<-20901, -52421> velocity=< 2,  5>
+position=< 42209,  21160> velocity=<-4, -2>
+position=< 21150, -31398> velocity=<-2,  3>
+position=< 31671, -20891> velocity=<-3,  2>
+position=<-20871, -52421> velocity=< 2,  5>
+position=<-10378,  52691> velocity=< 1, -5>
+position=<-10338, -20886> velocity=< 1,  2>
+position=<-52420, -20888> velocity=< 5,  2>
+position=< 10676,  52690> velocity=<-1, -5>
+position=<-10394, -41914> velocity=< 1,  4>
+position=<-41869, -41910> velocity=< 4,  4>
+position=< 52693,  52688> velocity=<-5, -5>
+position=< 10629,  10641> velocity=<-1, -1>
+position=<-20848, -10381> velocity=< 2,  1>
+position=<-31400,  31668> velocity=< 3, -3>
+position=<-31375,  42174> velocity=< 3, -4>
+position=<-10378, -41909> velocity=< 1,  4>
+position=< 21181,  31672> velocity=<-2, -3>
+position=<-41882,  21160> velocity=< 4, -2>
+position=< 52688,  42179> velocity=<-5, -4>
+position=<-41879, -31399> velocity=< 4,  3>
+position=<-41914, -41907> velocity=< 4,  4>
+position=<-10358,  21156> velocity=< 1, -2>
+position=< 21164, -20892> velocity=<-2,  2>
+position=<-20849, -31394> velocity=< 2,  3>
+position=< 21179, -10381> velocity=<-2,  1>
+position=<-20897, -41910> velocity=< 2,  4>
+position=< 31711, -31401> velocity=<-3,  3>
+position=< 42177, -41911> velocity=<-4,  4>
+position=< 42169, -31401> velocity=<-4,  3>
+position=<-31368,  31666> velocity=< 3, -3>
+position=<-10338,  42178> velocity=< 1, -4>
+position=< 10681, -31394> velocity=<-1,  3>
+position=<-52401, -10378> velocity=< 5,  1>
+position=< 52672,  31667> velocity=<-5, -3>
+position=< 10647, -31399> velocity=<-1,  3>
+position=< 10672,  42183> velocity=<-1, -4>
+position=<-52398, -10375> velocity=< 5,  1>
+position=<-31398, -31399> velocity=< 3,  3>
+position=< 31675, -52416> velocity=<-3,  5>
+position=<-31389, -10381> velocity=< 3,  1>
+position=< 42170,  10643> velocity=<-4, -1>
+position=<-52389, -10377> velocity=< 5,  1>
+position=<-31371, -41911> velocity=< 3,  4>
+position=< 52672,  52692> velocity=<-5, -5>
+position=< 31677, -41905> velocity=<-3,  4>
+position=< 21155, -31395> velocity=<-2,  3>
+position=< 10686,  52689> velocity=<-1, -5>
+position=< 21165,  31663> velocity=<-2, -3>
+position=<-10373,  42176> velocity=< 1, -4>
+position=< 31662, -10374> velocity=<-3,  1>
+position=< 31671, -31395> velocity=<-3,  3>
+position=<-10386, -52418> velocity=< 1,  5>
+position=<-41898,  10649> velocity=< 4, -1>
+position=<-31357, -52421> velocity=< 3,  5>
+position=<-20849,  52688> velocity=< 2, -5>
+position=<-52428,  10645> velocity=< 5, -1>
+position=<-52396, -41914> velocity=< 5,  4>
+position=< 21187,  52686> velocity=<-2, -5>
+position=< 10689,  42175> velocity=<-1, -4>
+position=< 21147,  21152> velocity=<-2, -2>
+position=< 52713, -52421> velocity=<-5,  5>
+position=<-41906, -52416> velocity=< 4,  5>
+position=< 42188, -31398> velocity=<-4,  3>
+position=<-52394, -20888> velocity=< 5,  2>
+position=<-41924, -52421> velocity=< 4,  5>
+position=< 31703, -31395> velocity=<-3,  3>
+position=<-10378, -52421> velocity=< 1,  5>
+position=<-20881,  10642> velocity=< 2, -1>
+position=< 31682,  21154> velocity=<-3, -2>
+position=< 31710,  21158> velocity=<-3, -2>
+position=<-41911, -20883> velocity=< 4,  2>
+position=< 10652,  31666> velocity=<-1, -3>
+position=< 42173, -41906> velocity=<-4,  4>
+position=<-10382, -41907> velocity=< 1,  4>
+position=<-20888, -52421> velocity=< 2,  5>
+position=<-10333, -31400> velocity=< 1,  3>
+position=< 21148, -52424> velocity=<-2,  5>
+position=<-31398, -10381> velocity=< 3,  1>
+position=< 42185,  42180> velocity=<-4, -4>
+position=< 21187, -52424> velocity=<-2,  5>
+position=<-20864,  10641> velocity=< 2, -1>
+position=< 31684, -31403> velocity=<-3,  3>
+position=< 21152, -41910> velocity=<-2,  4>
+position=< 42174, -20888> velocity=<-4,  2>
+position=< 42169,  52691> velocity=<-4, -5>
+position=<-10394, -20884> velocity=< 1,  2>
+position=<-41919,  31671> velocity=< 4, -3>
+position=<-52388,  10645> velocity=< 5, -1>
+position=< 21165, -31394> velocity=<-2,  3>
+position=<-41898,  10646> velocity=< 4, -1>
+position=<-52385,  10647> velocity=< 5, -1>
diff --git a/problems/day10.html b/problems/day10.html
new file mode 100644 (file)
index 0000000..c02bb3f
--- /dev/null
@@ -0,0 +1,253 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<meta charset="utf-8"/>
+<title>Day 10 - Advent of Code 2018</title>
+<!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
+<link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
+<link rel="stylesheet" type="text/css" href="/static/style.css?18"/>
+<link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
+<link rel="shortcut icon" href="/favicon.png"/>
+</head><!--
+
+
+
+
+Oh, hello!  Funny seeing you here.
+
+I appreciate your enthusiasm, but you aren't going to find much down here.
+There certainly aren't clues to any of the puzzles.  The best surprises don't
+even appear in the source until you unlock them for real.
+
+Please be careful with automated requests; I'm not Google, and I can only take
+so much traffic.  Please be considerate so that everyone gets to play.
+
+If you're curious about how Advent of Code works, it's running on some custom
+Perl code. Other than a few integrations (auth, analytics, ads, social media),
+I built the whole thing myself, including the design, animations, prose, and
+all of the puzzles.
+
+The puzzles are most of the work; the easiest ones take 3-4 hours each, but the
+harder ones take 6-8 hours, and a few even longer than that. A lot of effort
+went into building this thing - I hope you're enjoying playing it as much as I
+enjoyed making it for you!
+
+If you'd like to hang out, I'm @ericwastl on Twitter.
+
+- Eric Wastl
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+-->
+<body>
+<header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2018/about">[About]</a></li><li><a href="/2018/events">[Events]</a></li><li><a href="https://teespring.com/adventofcode" target="_blank">[Shop]</a></li><li><a href="/2018/settings">[Settings]</a></li><li><a href="/2018/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2018/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">20*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">//</span><a href="/2018">2018</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2018">[Calendar]</a></li><li><a href="/2018/support">[AoC++]</a></li><li><a href="/2018/sponsors">[Sponsors]</a></li><li><a href="/2018/leaderboard">[Leaderboard]</a></li><li><a href="/2018/stats">[Stats]</a></li></ul></nav></div></header>
+
+<div id="sidebar">
+<div id="sponsor"><div class="quiet">Our <a href="/2018/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://clubhouse.io/?utm_source=spon&amp;utm_medium=ch&amp;utm_campaign=aoc2018" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);" rel="noopener">Clubhouse</a> - The first project management platform for software development that brings everyone on every team together to build better products. AoC participants get two free months by signing up at r.clbh.se/mze9q9P Also, we're hiring!</div></div>
+</div><!--/sidebar-->
+
+<main>
+<article class="day-desc"><h2>--- Day 10: The Stars Align ---</h2><p>It's no use; your navigation system simply isn't capable of providing <span title="At the iceberg, use any lane to turn left. Then, swim for eight thousand miles.">walking directions</span> in the arctic circle, and certainly not in 1018.</p>
+<p>The Elves suggest an alternative. In times like these, North Pole rescue operations will arrange points of light in the sky to guide missing Elves back to base. Unfortunately, the message is easy to miss: the points move slowly enough that it takes hours to align them, but have so much momentum that they only stay aligned for a second. If you blink at the wrong time, it might be hours before another message appears.</p>
+<p>You can see these points of light floating in the distance, and record their position in the sky and their velocity, the relative change in position per second (your puzzle input). The coordinates are all given from your perspective; given enough time, those positions and velocities will move the points into a cohesive message!</p>
+<p>Rather than wait, you decide to fast-forward the process and calculate what the points will eventually spell.</p>
+<p>For example, suppose you note the following points:</p>
+<pre><code>position=< 9,  1> velocity=< 0,  2>
+position=< 7,  0> velocity=<-1,  0>
+position=< 3, -2> velocity=<-1,  1>
+position=< 6, 10> velocity=<-2, -1>
+position=< 2, -4> velocity=< 2,  2>
+position=<-6, 10> velocity=< 2, -2>
+position=< 1,  8> velocity=< 1, -1>
+position=< 1,  7> velocity=< 1,  0>
+position=<-3, 11> velocity=< 1, -2>
+position=< 7,  6> velocity=<-1, -1>
+position=<-2,  3> velocity=< 1,  0>
+position=<-4,  3> velocity=< 2,  0>
+position=<10, -3> velocity=<-1,  1>
+position=< 5, 11> velocity=< 1, -2>
+position=< 4,  7> velocity=< 0, -1>
+position=< 8, -2> velocity=< 0,  1>
+position=<15,  0> velocity=<-2,  0>
+position=< 1,  6> velocity=< 1,  0>
+position=< 8,  9> velocity=< 0, -1>
+position=< 3,  3> velocity=<-1,  1>
+position=< 0,  5> velocity=< 0, -1>
+position=<-2,  2> velocity=< 2,  0>
+position=< 5, -2> velocity=< 1,  2>
+position=< 1,  4> velocity=< 2,  1>
+position=<-2,  7> velocity=< 2, -2>
+position=< 3,  6> velocity=<-1, -1>
+position=< 5,  0> velocity=< 1,  0>
+position=<-6,  0> velocity=< 2,  0>
+position=< 5,  9> velocity=< 1, -2>
+position=<14,  7> velocity=<-2,  0>
+position=<-3,  6> velocity=< 2, -1>
+</code></pre>
+<p>Each line represents one point. Positions are given as <code>&lt;X, Y&gt;</code> pairs: X represents how far left (negative) or right (positive) the point appears, while Y represents how far up (negative) or down (positive) the point appears.</p>
+<p>At <code>0</code> seconds, each point has the position given. Each second, each point's velocity is added to its position. So, a point with velocity <code>&lt;1, -2&gt;</code> is moving to the right, but is moving upward twice as quickly. If this point's initial position were <code>&lt;3, 9&gt;</code>, after <code>3</code> seconds, its position would become <code>&lt;6, 3&gt;</code>.</p>
+<p>Over time, the points listed above would move like this:</p>
+<pre><code>Initially:
+........#.............
+................#.....
+.........#.#..#.......
+......................
+#..........#.#.......#
+...............#......
+....#.................
+..#.#....#............
+.......#..............
+......#...............
+...#...#.#...#........
+....#..#..#.........#.
+.......#..............
+...........#..#.......
+#...........#.........
+...#.......#..........
+
+After 1 second:
+......................
+......................
+..........#....#......
+........#.....#.......
+..#.........#......#..
+......................
+......#...............
+....##.........#......
+......#.#.............
+.....##.##..#.........
+........#.#...........
+........#...#.....#...
+..#...........#.......
+....#.....#.#.........
+......................
+......................
+
+After 2 seconds:
+......................
+......................
+......................
+..............#.......
+....#..#...####..#....
+......................
+........#....#........
+......#.#.............
+.......#...#..........
+.......#..#..#.#......
+....#....#.#..........
+.....#...#...##.#.....
+........#.............
+......................
+......................
+......................
+
+After 3 seconds:
+......................
+......................
+......................
+......................
+......#...#..###......
+......#...#...#.......
+......#...#...#.......
+......#####...#.......
+......#...#...#.......
+......#...#...#.......
+......#...#...#.......
+......#...#..###......
+......................
+......................
+......................
+......................
+
+After 4 seconds:
+......................
+......................
+......................
+............#.........
+........##...#.#......
+......#.....#..#......
+.....#..##.##.#.......
+.......##.#....#......
+...........#....#.....
+..............#.......
+....#......#...#......
+.....#.....##.........
+...............#......
+...............#......
+......................
+......................
+</code></pre>
+<p>After 3 seconds, the message appeared briefly: <code><em>HI</em></code>. Of course, your message will be much longer and will take many more seconds to appear.</p>
+<p><em>What message will eventually appear in the sky?</em></p>
+</article>
+<p>Your puzzle answer was <code>FNRGPBHR</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Good thing you didn't have to wait, because that would have taken a long time - much longer than the <code><em>3</em></code> seconds in the example above.</p>
+<p>Impressed by your sub-hour communication capabilities, the Elves are curious: <em>exactly how many seconds would they have needed to wait for that message to appear?</em></p>
+</article>
+<p>Your puzzle answer was <code>10511</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
+<p>At this point, you should <a href="/2018">return to your advent calendar</a> and try another puzzle.</p>
+<p>If you still want to see it, you can <a href="10/input" target="_blank">get your puzzle input</a>.</p>
+<p>You can also <span class="share">[Share<span class="share-content">on
+  <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22The+Stars+Align%22+%2D+Day+10+%2D+Advent+of+Code+2018&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F10&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
+  <a href="http://www.reddit.com/submit?url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F10&amp;title=I%27ve+completed+%22The+Stars+Align%22+%2D+Day+10+%2D+Advent+of+Code+2018" target="_blank">Reddit</a
+></span>]</span> this puzzle.</p>
+</main>
+
+<!-- ga -->
+<script>
+(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+ga('create', 'UA-69522494-1', 'auto');
+ga('send', 'pageview');
+</script>
+<!-- /ga -->
+</body>
+</html>
\ No newline at end of file
diff --git a/src/advent10/advent10-iterate-zip.hs b/src/advent10/advent10-iterate-zip.hs
new file mode 100644 (file)
index 0000000..ea26113
--- /dev/null
@@ -0,0 +1,117 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+import Data.List
+
+import Data.Text (Text)
+import qualified Data.Text.IO as TIO
+
+import Data.Void (Void)
+
+import Text.Megaparsec
+import Text.Megaparsec.Char
+import qualified Text.Megaparsec.Char.Lexer as L
+import qualified Control.Applicative as CA
+
+import qualified Data.Set as S
+
+type Coord = (Integer, Integer) -- x, y
+type Bounds = (Integer, Integer, Integer, Integer) -- minX, maxX, minY, maxY
+data Particle = Particle {_position :: Coord, _velocity :: Coord} deriving (Eq, Show)
+type Swarm = [Particle]
+type Grid = S.Set Coord
+
+main :: IO ()
+main = do 
+        text <- TIO.readFile "data/advent10.txt"
+        let particles = successfulParse text
+        let (final, time) = part0 particles
+        putStrLn $ showParticles final
+        print time
+
+part0 :: Swarm -> (Swarm, Int)
+part0 particles = (snd $ last $ gridPairs, length gridPairs)
+    where gridPairs = findEnd particles
+
+runParticles :: Swarm -> [Swarm]
+runParticles = iterate updateAll 
+
+findEnd :: Swarm -> [(Swarm, Swarm)]
+findEnd particles = takeWhile firstLarger gridPairs
+    where grids = runParticles particles
+          gridPairs = zip grids (drop 1 grids)
+          firstLarger (g1, g2) = (boundsArea g1) > (boundsArea g2)
+
+
+
+boundsArea :: Swarm -> Integer
+boundsArea particles = (maxX - minX) * (maxY - minY)
+    where (minX, maxX, minY, maxY) = findBounds particles
+
+findBounds :: Swarm -> Bounds 
+findBounds particles = 
+        ( minX -- small x edge
+        , maxX -- large x edge
+        , minY -- small x edge
+        , maxY -- large y edge
+        )
+    where maxX = maximum $ map (fst . _position) particles
+          minX = minimum $ map (fst . _position) particles
+          maxY = maximum $ map (snd . _position) particles
+          minY = minimum $ map (snd . _position) particles
+
+
+update :: Particle -> Particle
+update particle = particle {_position = (x + vx, y + vy)}
+    where (x, y) = _position particle
+          (vx, vy) = _velocity particle
+
+
+updateAll :: Swarm -> Swarm
+updateAll = map update
+
+showParticles :: Swarm -> String
+showParticles particles = intercalate "\n" rows
+    where (minX, maxX, minY, maxY) = findBounds particles
+          grid = S.fromList $ map _position particles
+          rows = [showRow y minX maxX grid | y <- [minY..maxY] ]
+
+showCell :: Integer -> Integer -> Grid -> Char
+showCell x y grid 
+    | (x, y) `S.member` grid = '*'
+    | otherwise = ' '
+
+showRow :: Integer -> Integer -> Integer -> Grid -> String
+showRow y minX maxX grid = [showCell x y grid | x <- [minX..maxX] ]
+
+-- Parse the input file
+
+type Parser = Parsec Void Text
+
+sc :: Parser ()
+sc = L.space (skipSome spaceChar) CA.empty CA.empty
+
+lexeme  = L.lexeme sc
+integer = lexeme L.decimal
+symb = L.symbol sc
+signedInteger = L.signed sc integer
+
+posPrefix = symb "position=<"
+velPrefix = symb "velocity=<"
+suffix = symb ">"
+commaP = symb ","
+
+particleFileP = many particleP
+
+particleP = particlify <$> positionP <*> velocityP 
+    where particlify x v = Particle x v
+
+positionP = posPrefix *> pairP <* suffix
+velocityP = velPrefix *> pairP <* suffix
+
+pairP = (,) <$> signedInteger <* commaP <*> signedInteger
+
+successfulParse :: Text -> Swarm
+successfulParse input = 
+        case parse particleFileP "input" input of
+                Left  _error -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
+                Right particles -> particles
\ No newline at end of file
diff --git a/src/advent10/advent10.hs b/src/advent10/advent10.hs
new file mode 100644 (file)
index 0000000..59d7c47
--- /dev/null
@@ -0,0 +1,118 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+import Data.List
+
+import Data.Text (Text)
+import qualified Data.Text.IO as TIO
+
+import Data.Void (Void)
+
+import Text.Megaparsec
+import Text.Megaparsec.Char
+import qualified Text.Megaparsec.Char.Lexer as L
+import qualified Control.Applicative as CA
+
+import qualified Data.Map.Strict as M
+import qualified Data.Set as S
+
+type Coord = (Integer, Integer) -- x, y
+type Bounds = (Integer, Integer, Integer, Integer) -- minX, maxX, minY, maxY
+data Particle = Particle {_position :: Coord, _velocity :: Coord} deriving (Eq, Show)
+type Grid = S.Set Coord
+
+main :: IO ()
+main = do 
+        text <- TIO.readFile "data/advent10.txt"
+        let particles = successfulParse text
+        -- putStrLn $ part1 particles
+        let (time, view) = part2 0 particles
+        putStrLn view
+        print time
+
+
+part1 particles 
+    | area' > area = showParticles particles
+    | otherwise = part1 particles'
+    where particles' = updateAll particles
+          area = boundsArea particles
+          area' = boundsArea particles'
+
+part2 time particles 
+    | area' > area = (time, showParticles particles)
+    | otherwise = part2 (time+1) particles'
+    where particles' = updateAll particles
+          area = boundsArea particles
+          area' = boundsArea particles'
+
+boundsArea :: [Particle] -> Integer
+boundsArea particles = (maxX - minX) * (maxY - minY)
+    where (minX, maxX, minY, maxY) = findBounds particles
+
+findBounds :: [Particle] -> Bounds 
+findBounds particles = 
+        ( minX -- small x edge
+        , maxX -- large x edge
+        , minY -- small x edge
+        , maxY -- large y edge
+        )
+    where maxX = maximum $ map (fst . _position) particles
+          minX = minimum $ map (fst . _position) particles
+          maxY = maximum $ map (snd . _position) particles
+          minY = minimum $ map (snd . _position) particles
+
+
+update :: Particle -> Particle
+update particle = particle {_position = (x + vx, y + vy)}
+    where (x, y) = _position particle
+          (vx, vy) = _velocity particle
+
+
+updateAll :: [Particle] -> [Particle]
+updateAll = map update
+
+showParticles :: [Particle] -> String
+showParticles particles = intercalate "\n" rows
+    where (minX, maxX, minY, maxY) = findBounds particles
+          grid = S.fromList $ map _position particles
+          rows = [showRow y minX maxX grid | y <- [minY..maxY] ]
+
+showCell :: Integer -> Integer -> Grid -> Char
+showCell x y grid 
+    | (x, y) `S.member` grid = '*'
+    | otherwise = ' '
+
+showRow :: Integer -> Integer -> Integer -> Grid -> String
+showRow y minX maxX grid = [showCell x y grid | x <- [minX..maxX] ]
+
+-- Parse the input file
+
+type Parser = Parsec Void Text
+
+sc :: Parser ()
+sc = L.space (skipSome spaceChar) CA.empty CA.empty
+
+lexeme  = L.lexeme sc
+integer = lexeme L.decimal
+symb = L.symbol sc
+signedInteger = L.signed sc integer
+
+posPrefix = symb "position=<"
+velPrefix = symb "velocity=<"
+suffix = symb ">"
+commaP = symb ","
+
+particleFileP = many particleP
+
+particleP = particlify <$> positionP <*> velocityP 
+    where particlify x v = Particle x v
+
+positionP = posPrefix *> pairP <* suffix
+velocityP = velPrefix *> pairP <* suffix
+
+pairP = (,) <$> signedInteger <* commaP <*> signedInteger
+
+successfulParse :: Text -> [Particle]
+successfulParse input = 
+        case parse particleFileP "input" input of
+                Left  _error -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
+                Right particles -> particles
\ No newline at end of file