Skip to content

Instantly share code, notes, and snippets.

@robmerrell
Last active August 29, 2015 14:07
Show Gist options
  • Save robmerrell/e8f80ec18e3fcdc3c67a to your computer and use it in GitHub Desktop.
Save robmerrell/e8f80ec18e3fcdc3c67a to your computer and use it in GitHub Desktop.
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