#! /usr/bin/env stack -- stack --resolver lts-12.20 --install-ghc script {-# LANGUAGE ViewPatterns #-} module Main where import Control.Arrow ((&&&)) import Data.Bifunctor (Bifunctor, bimap) import Data.Ix (range) main :: IO () main = interact $ (. (map parseLine . lines)) $ \points -> show $ let limits = (both minimum &&& both maximum) $ (map fst &&& map snd) points dist (x0,y0) (x1,y1) = abs (x0-x1) + abs (y0-y1) in length $ filter ((< 10000) . sum . flip map points . dist) $ range limits parseLine :: String -> (Int, Int) parseLine (break (==',') -> (read -> x, ',':' ':(read -> y))) = (x, y) both :: Bifunctor p => (a -> b) -> p a a -> p b b both f = bimap f f