Created
January 4, 2013 19:47
-
-
Save gpaulu/4455337 to your computer and use it in GitHub Desktop.
Attempt 2 at reddit challenge 115
This file contains hidden or 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
sumPair :: [Int] -> Int -> [(Int,Int)] | |
sumPair xs num = helper xs num [] | |
where helper [] _ [] = [] | |
helper [] _ [z] = [] | |
helper [] num (z:zs) = helper (z:zs) num [] | |
helper (x:[]) _ [] = [] | |
helper (x:[]) num zs = helper zs num [] | |
helper (x:y:xs) num [] | |
| x + y == num = (min x y,max x y):(helper xs num []) | |
| otherwise = helper (x:xs) num [y] | |
helper (x:y:xs) num [z] | |
| x + y == num = (min x y,max x y):(helper (z:xs) num []) | |
| otherwise = helper (x:xs) num (y:[z]) | |
helper (x:y:xs) num (z:zs) | |
| x + y == num = (min x y,max x y):(helper ((z:zs) ++ xs) num []) | |
| otherwise = helper (x:xs) num (y:z:zs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment