public
Created

  • Download Gist
findSum.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.