Created
March 8, 2018 13:24
-
-
Save samidarko/12adcbad5ded57ad2b189d4a89e01775 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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