summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2019/19.hs32
-rw-r--r--2019/19.in1
2 files changed, 33 insertions, 0 deletions
diff --git a/2019/19.hs b/2019/19.hs
new file mode 100644
index 0000000..17598b2
--- /dev/null
+++ b/2019/19.hs
@@ -0,0 +1,32 @@
+module Main where
+
+import Data.List
+import Data.Maybe
+
+import Input
+import IntCode
+
+
+main :: IO ()
+main = do
+ program <- parse . head <$> getInput 19
+
+ let samplePoint x y = head (snd (run program [x, y]))
+
+ print (sum [samplePoint x y | y <- [0..49], x <- [0..49]])
+
+ let pollDist = 1000
+ hitsAt d = let d' = fromIntegral d in [(x, y) | x <- [0..d'], let y = d' - x, samplePoint x y == 1]
+ pollHits = hitsAt pollDist
+
+ guessDist = 100 * pollDist `div` length pollHits
+ (minDist, maxDist) = (995 * guessDist `div` 1000, 1005 * guessDist `div` 1000)
+
+ hitsList = map hitsAt [minDist..maxDist]
+ dist = fromJust (findIndex ((>= 100) . length) hitsList) + minDist
+ finalHits = hitsList !! (dist - minDist)
+
+ (lbX, lbY) = head finalHits
+ ltY = lbY - 99
+
+ print (10000 * lbX + ltY)
diff --git a/2019/19.in b/2019/19.in
new file mode 100644
index 0000000..0cf79cd
--- /dev/null
+++ b/2019/19.in
@@ -0,0 +1 @@
+109,424,203,1,21101,0,11,0,1105,1,282,21101,0,18,0,1106,0,259,2102,1,1,221,203,1,21102,31,1,0,1105,1,282,21101,38,0,0,1105,1,259,21001,23,0,2,21201,1,0,3,21101,0,1,1,21101,0,57,0,1106,0,303,1202,1,1,222,20102,1,221,3,21002,221,1,2,21101,259,0,1,21102,80,1,0,1106,0,225,21101,0,189,2,21102,91,1,0,1105,1,303,2102,1,1,223,20101,0,222,4,21102,259,1,3,21101,225,0,2,21102,225,1,1,21102,1,118,0,1105,1,225,21001,222,0,3,21102,1,57,2,21102,1,133,0,1106,0,303,21202,1,-1,1,22001,223,1,1,21102,148,1,0,1106,0,259,1202,1,1,223,21001,221,0,4,20101,0,222,3,21101,0,24,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21101,195,0,0,106,0,108,20207,1,223,2,20102,1,23,1,21102,-1,1,3,21101,0,214,0,1106,0,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,1201,-4,0,249,22101,0,-3,1,22101,0,-2,2,22102,1,-1,3,21102,250,1,0,1106,0,225,22101,0,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,21201,-2,0,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,21201,-2,0,3,21102,343,1,0,1105,1,303,1105,1,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21201,-4,0,1,21101,384,0,0,1106,0,303,1106,0,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,22102,1,1,-4,109,-5,2105,1,0