-3

I have format LLNLN where L is Letter and N is number.

How can I print all possible strings, that match that format?

The output I'm expecting is

AA0A0
AA0A1
...
AA0A8
AA0A9
AA0B0
AA0B1
...
ZZ9Z9

MeeraWeeks
  • 83
  • 9
  • You can check out this: https://codereview.stackexchange.com/questions/122699/finding-a-cartesian-product-of-multiple-lists and try some code and share exactly where you're stuck. – vahdet Feb 26 '20 at 14:06
  • Duplicated question https://stackoverflow.com/questions/756055/listing-all-permutations-of-a-string-integer – Mohammad Nikravesh Feb 26 '20 at 14:12

2 Answers2

1

You can do it with LINQ for example:

var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var numbers = "0123456789";

var mutations =
    from m0 in letters
    from m1 in letters
    from m2 in numbers
    from m3 in letters
    from m4 in numbers
    select "" + m0 + m1 + m2 + m3 + m4;

foreach (var mutation in mutations)
{
    Console.WriteLine(mutation);    
}
Oskar Sjöberg
  • 2,728
  • 27
  • 31
  • Thank so much! That's exactly what I was looking for. Is there a way to create that expression dynamically? Eg. if I had sometimes 6 or 7 characters? – MeeraWeeks Feb 27 '20 at 10:28
0

I would write something like this (C#)

    string Letters = "ABCDEFGHIJKLMNOPQRSTUVYZ";
    foreach (Char l1 in Letters)
        foreach (Char l2 in Letters)
            for (int n1=0;n1 < 10;n1++)
                foreach (Char l3 in Letters)
                    for (int n2=0;n2 < 10;n2++)                         
                            Console.WriteLine(l1.ToString()+
                                              l2.ToString()+
                                              n1.ToString()+
                                              l3.ToString()+
                                              n2.ToString());