Created
October 2, 2014 21:50
-
-
Save lazyvalue/1e26f849be0c06d09e59 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
import Data.List | |
mylst = [(1,3), (2,4), (5,6), (5,7), (6,8)] | |
findOverlaps :: [(Int,Int)] -> [(Int,Int)] | |
findOverlaps xs = | |
let sorted = sortBy (\x y -> if ((fst x) < (fst y)) then LT else GT) xs | |
foldF acum elem = | |
let (doneLst, (blockMin,blockMax)) = acum | |
(elemMin, elemMax) = elem | |
in if elemMin > blockMax then | |
((blockMin,blockMax) : doneLst, elem) | |
else | |
(doneLst, (blockMin,elemMax)) | |
folded = foldl' foldF ([], head sorted) $ tail sorted | |
in reverse $ snd folded : fst folded | |
main = do | |
putStrLn $ show $ findOverlaps mylst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment