Advertisement
Guest User

3Sum

a guest
Feb 27th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List (nub, sort)
  2.  
  3. tsum' :: (Num a, Eq a) => [a] -> [a] -> [[a]]
  4. tsum' x y
  5.     | lenX < 3 && lenXY >= 3 = (tsum' (x ++ [headY]) tailY) ++ (tsum' x tailY)
  6.     | lenX == 3 && (sum x) == 0 = [x]
  7.     | otherwise = []
  8.     where lenX = length x
  9.           lenXY = lenX + length y
  10.           headY = head y
  11.           tailY = tail y
  12.  
  13. tsum :: (Ord a, Num a, Eq a) => [a] -> [[a]]
  14. tsum x = nub (tsum' [] (sort x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement