7
$\begingroup$

The length of license plate numbers is 6, with 2 letters and 4 numbers.

The first two characters are letters and the last four are numbers. Example: AA1234.

This is the code I have so far:

letterCombinations = Tuples[Alphabet[], 2];
numberCombinations = Tuples[Range[0,9], 4];

I tried to use Outer to combine the lists of letters and the lists of numbers, but it failed. How can I fix it, I want output like this:

{{a,a,1,1,1,1},......}

Is Outer a suitable?

$\endgroup$
2
  • $\begingroup$ How did you use Outer? Please show us the attempt. $\endgroup$
    – C. E.
    Feb 20 '17 at 9:43
  • $\begingroup$ As there are 6760000 possible license plates in the scheme you mentioned in the question, are you sure you really want to generate them all? If you only need a lot (but not all) maybe randomly generating as many as you need is a better solution. Try: With[{l := RandomChoice[Alphabet[]], n := RandomInteger[9]}, {l, l, n, n, n, n}] $\endgroup$
    – Sascha
    Feb 20 '17 at 9:47
15
$\begingroup$

I would use

a = Alphabet[]; (* letter *)
d = Range[0, 9]; (* digit *)

result = Tuples[{a, a, d, d, d, d}];
$\endgroup$
6
$\begingroup$

you can definitely use Outer if you prefer

a = Alphabet[];
b = Range[0,9];
list = Flatten[Outer[List, a,a,b,b,b,b], 5];
list//Length
(* 6760000 *)
$\endgroup$
2
$\begingroup$

Just to show how this can be done using the OP's proposed approach:

Flatten[Outer[Join, letterCombinations, numberCombinations, 1], 1]

The other responses are ~ 10x faster.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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