Skip to content

Instantly share code, notes, and snippets.

@angvillar
Last active August 23, 2020 15:04
Show Gist options
  • Save angvillar/b0ae47a49c7b4f2a7d4e1d3ea14b6bbb to your computer and use it in GitHub Desktop.
Save angvillar/b0ae47a49c7b4f2a7d4e1d3ea14b6bbb to your computer and use it in GitHub Desktop.
module Main where
import qualified Data.Map as Map
twoNumberSum :: Map.Map Int Bool -> [Int] -> Int -> [Int]
twoNumberSum _ [] _ = []
twoNumberSum m (x:xs) n = case (Map.lookup y m) of
Nothing -> twoNumberSum (Map.insert x True m) xs n
(Just _) -> [x,y]
where y = n-x
main :: IO ()
main = print (twoNumberSum (Map.fromList []) [1, 2, 3, 4, 5, 6, 7, 8, 9, 15] 18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment