Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Created August 20, 2011 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save md2perpe/1159478 to your computer and use it in GitHub Desktop.
Save md2perpe/1159478 to your computer and use it in GitHub Desktop.
import Data.List(find)
findSum :: Num a => a -> [a] -> Bool
findSum s ns = find (sumIs s) (pairs ns)
where
sumIs :: Num a => a -> (a, a) -> Bool
sumIs s (x, y) = x+y == s
pairs :: [a] -> [(a, a)]
pairs [] = []
pairs' (x:xs) = map (\y->(x,y)) xs ++ pairs xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment