Skip to content

anonymous /Crossing.hs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
import Data.List
main = interact $ unlines . map showSolution . zip [1..] . map solve . parseProblems
parseProblems = parse . map (map read . words) . tail . lines
where parse [] = []
parse ([n]:xs) = map (\ [x,y] -> (x,y)) (take n xs) : parse (drop n xs)
showSolution (n, s) = "Case #" ++ show n ++ ": " ++ show s
solve xs = sum [ fromEnum $ signum (l1-l2) /= signum (r1-r2) | (l1,r1):ys <- tails xs, (l2,r2) <- ys ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.