Skip to content

Instantly share code, notes, and snippets.

@gpaulu
Created January 4, 2013 19:47
Show Gist options
  • Save gpaulu/4455337 to your computer and use it in GitHub Desktop.
Save gpaulu/4455337 to your computer and use it in GitHub Desktop.
Attempt 2 at reddit challenge 115
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