diff options
author | tomsmeding <tom.smeding@gmail.com> | 2019-12-10 07:47:38 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2019-12-10 07:47:38 +0100 |
commit | a1e26f1f7a6131ee4bf15409ba18b07a431c37e5 (patch) | |
tree | 1d6e92ef7b5be18f9fa979967a731a22ad208188 /2019 | |
parent | 4a456c4e939942b81d2c4dd7744a1df0bdd85464 (diff) |
Day 10 part 1
Diffstat (limited to '2019')
-rw-r--r-- | 2019/10.hs | 22 | ||||
-rw-r--r-- | 2019/10.in | 26 |
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 @@ +#.#.###.#.#....#..##.#.... +.....#..#..#..#.#..#.....# +.##.##.##.##.##..#...#...# +#.#...#.#####...###.#.#.#. +.#####.###.#.#.####.#####. +#.#.#.##.#.##...####.#.##. +##....###..#.#..#..#..###. +..##....#.#...##.#.#...### +#.....#.#######..##.##.#.. +#.###.#..###.#.#..##.....# +##.#.#.##.#......#####..## +#..##.#.##..###.##.###..## +#..#.###...#.#...#..#.##.# +.#..#.#....###.#.#..##.#.# +#.##.#####..###...#.###.## +#...##..#..##.##.#.##..### +#.#.###.###.....####.##..# +######....#.##....###.#..# +..##.#.####.....###..##.#. +#..#..#...#.####..######.. +#####.##...#.#....#....#.# +.#####.##.#.#####..##.#... +#..##..##.#.##.##.####..## +.##..####..#..####.####### +#.#..#.##.#.######....##.. +.#.##.##.####......#.##.## |