Skip to content

Instantly share code, notes, and snippets.

@samidarko
Created March 8, 2018 13:24
Show Gist options
  • Save samidarko/12adcbad5ded57ad2b189d4a89e01775 to your computer and use it in GitHub Desktop.
Save samidarko/12adcbad5ded57ad2b189d4a89e01775 to your computer and use it in GitHub Desktop.
import qualified Data.Map as M
l = [5, 3, 7, 0, 1, 4, 2]
m = M.fromList [(x,x)| x <- l]
searchSumInList xs s =
let m = M.fromList [(x,x)| x <- xs]
in foldl fn [] $ zip [0..] l
where fn acc (i, e) = let t = s - e
in case M.lookup t m of
Just(v) -> if v /= i then (v, e) : acc else acc
_ -> acc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment