From a1e26f1f7a6131ee4bf15409ba18b07a431c37e5 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 10 Dec 2019 07:47:38 +0100 Subject: Day 10 part 1 --- 2019/10.hs | 22 ++++++++++++++++++++++ 2019/10.in | 26 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 2019/10.hs create mode 100644 2019/10.in 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 @@ +#.#.###.#.#....#..##.#.... +.....#..#..#..#.#..#.....# +.##.##.##.##.##..#...#...# +#.#...#.#####...###.#.#.#. +.#####.###.#.#.####.#####. +#.#.#.##.#.##...####.#.##. +##....###..#.#..#..#..###. +..##....#.#...##.#.#...### +#.....#.#######..##.##.#.. +#.###.#..###.#.#..##.....# +##.#.#.##.#......#####..## +#..##.#.##..###.##.###..## +#..#.###...#.#...#..#.##.# +.#..#.#....###.#.#..##.#.# +#.##.#####..###...#.###.## +#...##..#..##.##.#.##..### +#.#.###.###.....####.##..# +######....#.##....###.#..# +..##.#.####.....###..##.#. +#..#..#...#.####..######.. +#####.##...#.#....#....#.# +.#####.##.#.#####..##.#... +#..##..##.#.##.##.####..## +.##..####..#..####.####### +#.#..#.##.#.######....##.. +.#.##.##.####......#.##.## -- cgit v1.2.3-70-g09d2