Skip to content

Instantly share code, notes, and snippets.

Created August 16, 2010 08:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/526610 to your computer and use it in GitHub Desktop.
Save anonymous/526610 to your computer and use it in GitHub Desktop.
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