Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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