public
anonymous / Crossing.hs
Created

  • Download Gist
Crossing.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11
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 ]

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.