09.hs
edited
1import Data.List.Split (splitOn)
2
3parse = map (map read . splitOn ",") . lines
4
5area [x, y] [x', y'] = (1 + abs (x - x')) * (1 + abs (y - y'))
6
7p1 poly = maximum [area p p' | p <- poly, p' <- poly]
8
9p2 poly = maximum [area p p' | p <- poly, p' <- poly, not (intersects p p' poly)]
10
11intersects [x, y] [x', y'] = not . all away . pairs
12 where
13 pairs (p : ps) = zip (p : ps) (ps ++ [p])
14 away ([lx, ly], [lx', ly']) =
15 (max lx lx' <= min x x')
16 || (min lx lx' >= max x x')
17 || (max ly ly' <= min y y')
18 || (min ly ly' >= max y y')
19
20main = do
21 n <- parse <$> getContents
22 print $ p1 n
23 print $ p2 n