-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday08.hs
More file actions
17 lines (12 loc) · 699 Bytes
/
Copy pathday08.hs
File metadata and controls
17 lines (12 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Main where
import Data.Map.Strict qualified as M
import Data.Set qualified as S
main = interact (unlines . sequence [part1, part2] . scan)
part1 = ("Part 1: " ++) . show . length . antinodes [1]
part2 = ("Part 2: " ++) . show . length . antinodes [0 .. 50]
antinodes n = inMap (S.unions . S.map (uncurry offset) . pairs)
where
pairs = S.filter (uncurry (/=)) . (S.cartesianProduct <*> id)
inMap f = (S.intersection . S.unions) <*> (S.unions . M.map f . M.delete '.')
offset (x, y) (x', y') = S.fromList [(x + i * (x - x'), y + i * (y - y')) | i <- n]
scan input = M.fromListWith S.union [(c, S.singleton (x, y)) | (l, y) <- zip (lines input) [0 ..], (c, x) <- zip l [0 ..]]