Last active
August 29, 2015 14:07
-
-
Save robmerrell/e8f80ec18e3fcdc3c67a 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
defmodule ListPairs do | |
defp _find([], _, acc), do: acc | |
defp _find([h|t], target_sum, acc) do | |
accepted_pairs = Enum.filter_map t, &(&1 + h == target_sum), &({h, &1}) | |
_find(t, target_sum, acc ++ accepted_pairs) | |
end | |
def find(list, target_sum) do | |
_find(list, target_sum, []) | |
end | |
end | |
IO.puts inspect ListPairs.find([1, 2, 8, 3, 4, 7], 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment