I want to create an alphanumeric sequence using numbers from 0 to 9 and the alphabet. The sequence will be 4 characters long, I ask the user to indicate which sequence to start with and how many of the sequence to create.
I have the following code with which I get the position of the sequence that the user indicated, but I don't know how to start the sequence from the position of each character or number.
In the variable string secuenciainiciada="";
I store the position of each of the characters that have the sequence that the user indicated; In this case, when I run the program, it returns this position 11,2,22,9
: from here it will start to increase by one.
string[] arraynumeros = new string[10] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
string[] arrayletras = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", };
int total = 30;
string IniSecuencia = "LCWJ";
int indices;
string secuenciainiciada="";
for (int i = 0; i < IniSecuencia.Length; i++)
{
if (Regex.IsMatch(IniSecuencia.Substring(i,1), @"^[0-9]+$"))
{
indices = Array.IndexOf(arraynumeros, IniSecuencia.Substring(i, 1));
}
else
{
indices = Array.IndexOf(arrayletras, IniSecuencia.Substring(i, 1));
}
secuenciainiciada += Convert.ToString(indices + ",");
}
This is an example of the sequence that should return to me if I ask for 30 sequences and I tell it to start in LCWJ, it has to increase one by one and always from right to left.
LCWJ
LCWK
LCWL
LCWM
LCWN
LCWO
LCWP
LCWQ
LCWR
LCWS
LCWT
LCWU
LCWW
LCWX
LCWY
LCWZ
LCX0
LCX1
LCX2
LCX3
LCX4
LCX5
LCX6
LCX7
LCX8
LCX9
LCXA
LCXB
LCXC
LCXD
LCXF
The first thing is that your output example is wrong, you have 31 items and not 30, then you skip LCWU to LCWW, there you have to go through LCWV
Then you have to join the 2 arrays into one (the one with numbers and letters), because otherwise it's a mess.
What you have is the same as a number in base 36, and a possible solution is to work as such, you go to base 10 add 1 and go to base 36. I think this is not very efficient for this case.
What I propose is to have an Array with the positions of each letter of the input string. For example, the input is "BA" the array would have [11,10]. The next number must be added 1 to the last item of the array, that is, the sequence would be
(This logic is what I think you were trying to do)
Let's go to the code: