combination of the given list

Hey
How could I get all combination of the given list where each item in the list is a tuple and the combination should be made based on the second element. The second element is a list containing minium one and maximum four atoms.

Input:

[
    {{1, 1}, [:w, :e]},
    {{1, 3}, [:e]},
    {{2, 3}, [:n, :s]}
]

Output:

[
      [
        {{1, 1}, [:w]},
        {{1, 3}, [:e]},
        {{2, 3}, [:n]}
      ],
      [
        {{1, 1}, [:w]},
        {{1, 3}, [:e]},
        {{2, 3}, [:s]}
      ],
      [
        {{1, 1}, [:e]},
        {{1, 3}, [:e]},
        {{2, 3}, [:n]}
      ],
      [
        {{1, 1}, [:e]},
        {{1, 3}, [:e]},
        {{2, 3}, [:s]}
      ]
    ]

edit:

  • its a subtask of a homework i encountered, so i cannot provide a source
  • ive read the first ~10 chapters of this guide

Welcome Perry :023:

You missed some info from the template, please answer the following:

  • The source of the question/test (place the URL in single backticks if necessary)
  • What you have tried to answer the question yourself
  • Which sections of the Elixir or Phoenix manual/guides* you have read
  • Include anything else needed for people to help you

*Learning resources - The Elixir programming language and Overview — Phoenix v1.7.10

4 Likes