Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created with

Tuples[{{USD, EUR, JPY}, {UP, DOWN}}]

the following result:

{{USD, UP}, {USD, DOWN}, {EUR, UP}, {EUR, DOWN}, {JPY, UP}, {JPY, DOWN}}

I want to further have a 3 dimensional list of all combinations - but the same currency does not appear twice. Example output

{{{USD, UP}, {EUR, UP}, {JPY, UP}}, {{USD, UP}, {EUR, UP}, {JPY, DOWN}}, {{USD, UP}, {EUR, DOWN}, {JPY, UP}}, {{USD, UP}, {EUR, DOWN}, {JPY, DOWN}}, ... {{USD, DOWN}, {EUR, DOWN}, {JPY, DOWN}}}

Is there a simple way to do it?

share|improve this question

Here is one way:

Tuples@Outer[List, {USD, EUR, JPY}, {UP, DOWN}]
(*
  {{{USD, UP}, {EUR, UP}, {JPY, UP}},
   {{USD, UP}, {EUR, UP}, {JPY, DOWN}},
   {{USD, UP}, {EUR, DOWN}, {JPY, UP}},
   {{USD, UP}, {EUR, DOWN}, {JPY, DOWN}},
   {{USD, DOWN}, {EUR, UP}, {JPY, UP}},
   {{USD, DOWN}, {EUR, UP}, {JPY, DOWN}},
   {{USD, DOWN}, {EUR, DOWN}, {JPY, UP}},
   {{USD, DOWN}, {EUR, DOWN}, {JPY, DOWN}}}
*)
share|improve this answer
    
I can't beat that. I tried. :-) – Mr.Wizard Jul 18 '14 at 13:12
    
@Mr.Wizard Thanks! – Michael E2 Jul 18 '14 at 13:19

Yes, one way is to use Tuples again after some judicious partitioning:

Tuples[Partition[Tuples[{{"USD", "EUR", "JPY"}, {"UP", "DOWN"}}], 2]]

Note the 2 is the length of the second set in the original Tuples so you could write your own function:

myTuples[list1_List, list2_List] := Tuples[Partition[Tuples[{list1, list2}], Length[list2]]]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.