summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2019/10.hs22
-rw-r--r--2019/10.in26
2 files changed, 48 insertions, 0 deletions
diff --git a/2019/10.hs b/2019/10.hs
new file mode 100644
index 0000000..5b6e09c
--- /dev/null
+++ b/2019/10.hs
@@ -0,0 +1,22 @@
+module Main where
+
+import Data.Array.Unboxed
+
+import Input
+
+main :: IO ()
+main = do
+ inp <- getInput 10
+ let h = length inp
+ w = length (head inp)
+ arr = listArray ((0, 0), (w-1, h-1)) (concatMap (map (== '#')) inp)
+ :: UArray (Int, Int) Bool
+ asts = map fst (filter snd (assocs arr))
+ sight (a,b) (x,y) =
+ let dx = (x - a) `div` g
+ dy = (y - b) `div` g
+ g = gcd (abs (x - a)) (abs (y - b))
+ pts = [(a + i * dx, b + i * dy) | i <- [1..g-1]]
+ in all (not . (arr !)) pts
+ numVisible p = length (filter (\q -> q /= p && sight p q) asts)
+ print (maximum (map numVisible asts))
diff --git a/2019/10.in b/2019/10.in
new file mode 100644
index 0000000..defc148
--- /dev/null
+++ b/2019/10.in
@@ -0,0 +1,26 @@
+#.#.###.#.#....#..##.#....
+.....#..#..#..#.#..#.....#
+.##.##.##.##.##..#...#...#
+#.#...#.#####...###.#.#.#.
+.#####.###.#.#.####.#####.
+#.#.#.##.#.##...####.#.##.
+##....###..#.#..#..#..###.
+..##....#.#...##.#.#...###
+#.....#.#######..##.##.#..
+#.###.#..###.#.#..##.....#
+##.#.#.##.#......#####..##
+#..##.#.##..###.##.###..##
+#..#.###...#.#...#..#.##.#
+.#..#.#....###.#.#..##.#.#
+#.##.#####..###...#.###.##
+#...##..#..##.##.#.##..###
+#.#.###.###.....####.##..#
+######....#.##....###.#..#
+..##.#.####.....###..##.#.
+#..#..#...#.####..######..
+#####.##...#.#....#....#.#
+.#####.##.#.#####..##.#...
+#..##..##.#.##.##.####..##
+.##..####..#..####.#######
+#.#..#.##.#.######....##..
+.#.##.##.####......#.##.##