summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-12-22 08:39:35 +0100
committertomsmeding <tom.smeding@gmail.com>2019-12-22 08:39:35 +0100
commit348f30a95b33908777e1b9ca4f1490cf417d195c (patch)
tree7abd1e88237e9964bc65da4fc512f4cf54aa0278
parentdc2eea09900d0baa73768ff205d86690a92964c9 (diff)
Day 21
-rw-r--r--2019/21.hs33
-rw-r--r--2019/21.in1
2 files changed, 34 insertions, 0 deletions
diff --git a/2019/21.hs b/2019/21.hs
new file mode 100644
index 0000000..d65f0ab
--- /dev/null
+++ b/2019/21.hs
@@ -0,0 +1,33 @@
+module Main where
+
+import Data.Char
+
+import Input
+import IntCode
+
+
+main :: IO ()
+main = do
+ program <- parse . head <$> getInput 21
+
+ let springcode1 = "NOT A T\nNOT B J\nOR J T\nNOT C J\nOR T J\nAND D J\nWALK\n"
+
+ -- let loop cont inp =
+ -- case runContinue cont inp of
+ -- Left (cont', out) -> do
+ -- putStr (map (chr . fromIntegral) out)
+ -- line <- map (fromIntegral . ord) <$> getLine
+ -- loop cont' (line ++ [10])
+ -- Right (_, out) ->
+ -- putStr (map (chr . fromIntegral) out)
+
+ -- loop (initialContinuation program) []
+
+ let output1 = snd (run program (map (fromIntegral . ord) springcode1))
+ print (last output1)
+
+ let springcode2 = "NOT A T\nNOT B J\nOR J T\nNOT C J\nOR T J\nAND D J\nNOT E T\nNOT T T\nOR H T\nAND T J\nRUN\n"
+
+ let output2 = snd (run program (map (fromIntegral . ord) springcode2))
+ -- putStr (map (chr . fromIntegral) output2)
+ print (last output2)
diff --git a/2019/21.in b/2019/21.in
new file mode 100644
index 0000000..8dc2bc6
--- /dev/null
+++ b/2019/21.in
@@ -0,0 +1 @@
+109,2050,21102,966,1,1,21102,1,13,0,1105,1,1378,21101,0,20,0,1106,0,1337,21102,1,27,0,1105,1,1279,1208,1,65,748,1005,748,73,1208,1,79,748,1005,748,110,1208,1,78,748,1005,748,132,1208,1,87,748,1005,748,169,1208,1,82,748,1005,748,239,21102,1,1041,1,21102,1,73,0,1105,1,1421,21101,0,78,1,21101,0,1041,2,21101,88,0,0,1105,1,1301,21102,68,1,1,21102,1041,1,2,21102,1,103,0,1106,0,1301,1102,1,1,750,1106,0,298,21101,0,82,1,21101,1041,0,2,21101,125,0,0,1106,0,1301,1102,1,2,750,1106,0,298,21102,79,1,1,21102,1041,1,2,21102,1,147,0,1105,1,1301,21102,84,1,1,21102,1,1041,2,21101,0,162,0,1106,0,1301,1102,3,1,750,1106,0,298,21101,65,0,1,21101,0,1041,2,21101,184,0,0,1105,1,1301,21101,76,0,1,21101,0,1041,2,21102,1,199,0,1105,1,1301,21102,75,1,1,21102,1,1041,2,21102,1,214,0,1105,1,1301,21102,1,221,0,1106,0,1337,21102,1,10,1,21102,1,1041,2,21101,236,0,0,1105,1,1301,1106,0,553,21101,0,85,1,21101,0,1041,2,21101,254,0,0,1106,0,1301,21102,1,78,1,21102,1,1041,2,21102,269,1,0,1105,1,1301,21102,276,1,0,1105,1,1337,21102,10,1,1,21102,1,1041,2,21101,0,291,0,1105,1,1301,1102,1,1,755,1105,1,553,21101,32,0,1,21101,1041,0,2,21102,1,313,0,1105,1,1301,21101,320,0,0,1106,0,1337,21101,0,327,0,1106,0,1279,2102,1,1,749,21102,1,65,2,21101,0,73,3,21101,346,0,0,1106,0,1889,1206,1,367,1007,749,69,748,1005,748,360,1102,1,1,756,1001,749,-64,751,1105,1,406,1008,749,74,748,1006,748,381,1102,1,-1,751,1106,0,406,1008,749,84,748,1006,748,395,1102,-2,1,751,1105,1,406,21101,1100,0,1,21102,406,1,0,1106,0,1421,21101,0,32,1,21102,1,1100,2,21102,421,1,0,1105,1,1301,21102,1,428,0,1105,1,1337,21102,435,1,0,1106,0,1279,1201,1,0,749,1008,749,74,748,1006,748,453,1101,0,-1,752,1105,1,478,1008,749,84,748,1006,748,467,1102,1,-2,752,1106,0,478,21101,0,1168,1,21101,478,0,0,1105,1,1421,21102,1,485,0,1105,1,1337,21101,0,10,1,21101,1168,0,2,21101,500,0,0,1106,0,1301,1007,920,15,748,1005,748,518,21102,1209,1,1,21102,1,518,0,1105,1,1421,1002,920,3,529,1001,529,921,529,102,1,750,0,1001,529,1,537,1002,751,1,0,1001,537,1,545,101,0,752,0,1001,920,1,920,1106,0,13,1005,755,577,1006,756,570,21102,1,1100,1,21101,570,0,0,1105,1,1421,21102,987,1,1,1106,0,581,21102,1,1001,1,21102,588,1,0,1105,1,1378,1101,0,758,593,1001,0,0,753,1006,753,654,21001,753,0,1,21102,610,1,0,1105,1,667,21101,0,0,1,21102,1,621,0,1105,1,1463,1205,1,647,21102,1015,1,1,21102,635,1,0,1106,0,1378,21102,1,1,1,21101,646,0,0,1105,1,1463,99,1001,593,1,593,1105,1,592,1006,755,664,1101,0,0,755,1106,0,647,4,754,99,109,2,1102,726,1,757,22102,1,-1,1,21101,0,9,2,21102,697,1,3,21101,692,0,0,1105,1,1913,109,-2,2105,1,0,109,2,1002,757,1,706,1201,-1,0,0,1001,757,1,757,109,-2,2105,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,255,63,159,127,95,191,223,0,100,222,49,174,92,179,110,252,184,172,46,189,93,139,118,203,122,243,251,249,186,200,177,111,99,168,182,125,236,98,196,162,244,197,230,167,238,173,235,237,56,35,114,212,155,47,170,220,152,50,43,153,109,115,126,53,54,199,87,204,226,58,101,198,38,227,166,216,250,79,124,178,157,117,143,221,102,231,213,86,76,205,119,71,42,206,120,218,142,69,116,78,121,113,61,140,94,175,254,136,60,59,246,201,51,214,57,70,228,154,137,215,169,84,34,103,217,85,138,242,141,241,248,183,190,39,239,171,107,207,181,108,55,163,253,68,202,232,106,158,234,188,229,77,187,219,156,245,247,185,62,123,233,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,73,110,112,117,116,32,105,110,115,116,114,117,99,116,105,111,110,115,58,10,13,10,87,97,108,107,105,110,103,46,46,46,10,10,13,10,82,117,110,110,105,110,103,46,46,46,10,10,25,10,68,105,100,110,39,116,32,109,97,107,101,32,105,116,32,97,99,114,111,115,115,58,10,10,58,73,110,118,97,108,105,100,32,111,112,101,114,97,116,105,111,110,59,32,101,120,112,101,99,116,101,100,32,115,111,109,101,116,104,105,110,103,32,108,105,107,101,32,65,78,68,44,32,79,82,44,32,111,114,32,78,79,84,67,73,110,118,97,108,105,100,32,102,105,114,115,116,32,97,114,103,117,109,101,110,116,59,32,101,120,112,101,99,116,101,100,32,115,111,109,101,116,104,105,110,103,32,108,105,107,101,32,65,44,32,66,44,32,67,44,32,68,44,32,74,44,32,111,114,32,84,40,73,110,118,97,108,105,100,32,115,101,99,111,110,100,32,97,114,103,117,109,101,110,116,59,32,101,120,112,101,99,116,101,100,32,74,32,111,114,32,84,52,79,117,116,32,111,102,32,109,101,109,111,114,121,59,32,97,116,32,109,111,115,116,32,49,53,32,105,110,115,116,114,117,99,116,105,111,110,115,32,99,97,110,32,98,101,32,115,116,111,114,101,100,0,109,1,1005,1262,1270,3,1262,20101,0,1262,0,109,-1,2105,1,0,109,1,21102,1,1288,0,1105,1,1263,21001,1262,0,0,1101,0,0,1262,109,-1,2106,0,0,109,5,21102,1310,1,0,1105,1,1279,21201,1,0,-2,22208,-2,-4,-1,1205,-1,1332,21202,-3,1,1,21102,1,1332,0,1105,1,1421,109,-5,2105,1,0,109,2,21102,1,1346,0,1106,0,1263,21208,1,32,-1,1205,-1,1363,21208,1,9,-1,1205,-1,1363,1106,0,1373,21101,0,1370,0,1106,0,1279,1105,1,1339,109,-2,2106,0,0,109,5,1201,-4,0,1386,20101,0,0,-2,22101,1,-4,-4,21102,1,0,-3,22208,-3,-2,-1,1205,-1,1416,2201,-4,-3,1408,4,0,21201,-3,1,-3,1105,1,1396,109,-5,2105,1,0,109,2,104,10,22102,1,-1,1,21101,0,1436,0,1105,1,1378,104,10,99,109,-2,2105,1,0,109,3,20002,593,753,-1,22202,-1,-2,-1,201,-1,754,754,109,-3,2106,0,0,109,10,21102,5,1,-5,21101,0,1,-4,21101,0,0,-3,1206,-9,1555,21101,3,0,-6,21102,1,5,-7,22208,-7,-5,-8,1206,-8,1507,22208,-6,-4,-8,1206,-8,1507,104,64,1106,0,1529,1205,-6,1527,1201,-7,716,1515,21002,0,-11,-8,21201,-8,46,-8,204,-8,1106,0,1529,104,46,21201,-7,1,-7,21207,-7,22,-8,1205,-8,1488,104,10,21201,-6,-1,-6,21207,-6,0,-8,1206,-8,1484,104,10,21207,-4,1,-8,1206,-8,1569,21101,0,0,-9,1105,1,1689,21208,-5,21,-8,1206,-8,1583,21102,1,1,-9,1106,0,1689,1201,-5,716,1588,21001,0,0,-2,21208,-4,1,-1,22202,-2,-1,-1,1205,-2,1613,22102,1,-5,1,21102,1613,1,0,1105,1,1444,1206,-1,1634,22102,1,-5,1,21102,1,1627,0,1106,0,1694,1206,1,1634,21102,2,1,-3,22107,1,-4,-8,22201,-1,-8,-8,1206,-8,1649,21201,-5,1,-5,1206,-3,1663,21201,-3,-1,-3,21201,-4,1,-4,1105,1,1667,21201,-4,-1,-4,21208,-4,0,-1,1201,-5,716,1676,22002,0,-1,-1,1206,-1,1686,21102,1,1,-4,1106,0,1477,109,-10,2105,1,0,109,11,21102,1,0,-6,21101,0,0,-8,21101,0,0,-7,20208,-6,920,-9,1205,-9,1880,21202,-6,3,-9,1201,-9,921,1725,20102,1,0,-5,1001,1725,1,1733,20101,0,0,-4,22101,0,-4,1,21101,1,0,2,21101,9,0,3,21102,1,1754,0,1106,0,1889,1206,1,1772,2201,-10,-4,1766,1001,1766,716,1766,21001,0,0,-3,1105,1,1790,21208,-4,-1,-9,1206,-9,1786,21202,-8,1,-3,1105,1,1790,22101,0,-7,-3,1001,1733,1,1796,20101,0,0,-2,21208,-2,-1,-9,1206,-9,1812,21202,-8,1,-1,1106,0,1816,22102,1,-7,-1,21208,-5,1,-9,1205,-9,1837,21208,-5,2,-9,1205,-9,1844,21208,-3,0,-1,1105,1,1855,22202,-3,-1,-1,1106,0,1855,22201,-3,-1,-1,22107,0,-1,-1,1105,1,1855,21208,-2,-1,-9,1206,-9,1869,22102,1,-1,-8,1106,0,1873,22102,1,-1,-7,21201,-6,1,-6,1106,0,1708,22101,0,-8,-10,109,-11,2106,0,0,109,7,22207,-6,-5,-3,22207,-4,-6,-2,22201,-3,-2,-1,21208,-1,0,-6,109,-7,2106,0,0,0,109,5,2101,0,-2,1912,21207,-4,0,-1,1206,-1,1930,21102,0,1,-4,21201,-4,0,1,22101,0,-3,2,21102,1,1,3,21101,1949,0,0,1106,0,1954,109,-5,2105,1,0,109,6,21207,-4,1,-1,1206,-1,1977,22207,-5,-3,-1,1206,-1,1977,22102,1,-5,-5,1105,1,2045,21201,-5,0,1,21201,-4,-1,2,21202,-3,2,3,21102,1,1996,0,1105,1,1954,22102,1,1,-5,21102,1,1,-2,22207,-5,-3,-1,1206,-1,2015,21102,0,1,-2,22202,-3,-2,-3,22107,0,-4,-1,1206,-1,2037,21202,-2,1,1,21102,2037,1,0,105,1,1912,21202,-3,-1,-3,22201,-5,-3,-5,109,-6,2105,1,0