Created
August 4, 2010 07:16
-
-
Save njbartlett/507783 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
countCrossings :: TestCase -> Int | |
countCrossings = length . guardedPairs crosses | |
-- This is the "pairs" function from the first meeting, with the addition of a | |
-- predicate function to filter out unwanted pairs | |
guardedPairs :: (a -> a -> Bool) -> [a] -> [(a,a)] | |
guardedPairs p xs = [(x,y) | (x:ys) <- tails xs, y <- ys, p x y] | |
crosses :: Wire -> Wire -> Bool | |
crosses (Wire s1 e1) (Wire s2 e2) = if s1 < s2 then e1 > e2 else e1 < e2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment