Last active
April 13, 2017 01:59
-
-
Save dhanji/06f0a76ad0b2bfa5c9953e0e14e146ae 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
-- Using merge to efficiently intersect two lists | |
ages = [1, 2, 5, 6] | |
names = [1, 5, 6, 7, 8, 9] | |
addresses = [2, 3, 7, 9, 10] | |
siblings = [3, 5, 6, 9] | |
intersect [] [] = [] | |
intersect [] _ = [] | |
intersect _ [] = [] | |
intersect (x:xs) (y:ys) | |
| x == y = (x:intersect xs ys) | |
| x > y = intersect (x:xs) ys | |
| otherwise = intersect xs (y:ys) | |
main = putStrLn $ show $ intersect addresses siblings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment