part1, part2 :: [Sensor] -> Region -> Int
part1 sensors coverage = sum (fmap countForbidden rowChunks `using` (parList rseq))
- where -- coverage = mconcat $ fmap nearby $ sortOn Down sensors
- rowCoords = range ( (V2 (globalMinX sensors) thisY)
+ where rowCoords = range ( (V2 (globalMinX sensors) thisY)
, (V2 (globalMaxX sensors) thisY)
)
rowChunks = chunksOf 1000 rowCoords
occupied = concatMap (\(Sensor s b) -> [s, b]) sensors
- -- forbidden = (filter (\p -> p `notElem` occupied) $ filter (getRegion coverage) rowCoords) `using` (parList rpar)
- -- forbidden = (fmap (\p -> (getRegion coverage p, p)) rowCoords) `using` (parList rdeepseq)
countForbidden positions =
length $ filter (\p -> p `notElem` occupied)
$ filter (getRegion coverage) positions
part2 sensors coverage = x * 4000000 + y
- where -- coverage = mconcat $ fmap nearby $ sortOn Down sensors
- boundaries = fmap (filter (inRange searchRange))
+ where boundaries = fmap (filter (inRange searchRange))
$ fmap justOutside sensors
- -- holes = (fmap (filter (not . (getRegion coverage))) boundaries) `using` (parList rpar)
holes = fmap (filter (not . (getRegion coverage))) boundaries
`using` (parList rseq)
- -- holes = (fmap (filter (not . (getRegion coverage))) boundaries) `using` (parList rpar)
- -- holes = withStrategy (parList rpar) (fmap (filter (not . (getRegion coverage))) boundaries)
- -- holes = using (fmap (filter (not . (getRegion coverage))) boundaries) (parList rpar)
- -- holes = parMap rpar (filter (not . (getRegion coverage))) boundaries
V2 x y = head $ concat holes