640 B · 23 lines · Created 10mo ago
Haskell
1234567891011121314151617181920212223import Data.List.Split (splitOn)
parse = map (map read . splitOn ",") . lines
area [x, y] [x', y'] = (1 + abs (x - x')) * (1 + abs (y - y'))
p1 poly = maximum [area p p' | p <- poly, p' <- poly]
p2 poly = maximum [area p p' | p <- poly, p' <- poly, not (intersects p p' poly)]
intersects [x, y] [x', y'] = not . all away . pairs where pairs (p : ps) = zip (p : ps) (ps ++ [p]) away ([lx, ly], [lx', ly']) = (max lx lx' <= min x x') || (min lx lx' >= max x x') || (max ly ly' <= min y y') || (min ly ly' >= max y y')
main = do n <- parse <$> getContents print $ p1 n print $ p2 n