Skip to content

Instantly share code, notes, and snippets.

@BadBastion
Created May 9, 2017 01:57
Show Gist options
  • Save BadBastion/1fc5b07a394588e4bc49b700d9f7ca0c to your computer and use it in GitHub Desktop.
Save BadBastion/1fc5b07a394588e4bc49b700d9f7ca0c to your computer and use it in GitHub Desktop.
defmodule Test do
defp add(product, {i, list_i}, {j, list_j}, max) do
p = [{elem(list_i, i), elem(list_j, j)} | product]
reverse(p, {j, list_i}, {i+1, list_j}, max)
end
defp reverse(product, {i, list_i}, {j, list_j}, max) do
p = [{elem(list_i, i), elem(list_j, j)} | product]
case j do # next step?
^max -> p # done
^i -> reverse(p, {i+1, list_i}, {0, list_j}, max) # new
j -> add(p, {j , list_i}, {i, list_j}, max) # normal
end
end
def breadth_first_product(list1, list2) do
e = reverse([], {0, List.to_tuple(list1)}, {0, List.to_tuple(list2)}, length(list1)-1) |> Enum.reverse
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment