QuestionDisplacement of numbers

shahryars

New member
hi
i want to make an app, that Displacement numbers and add them in listbox
for example: when i give it 713, it should add 713,731,317,371,173,137 to listbox
but i don't know how to do it, please help me!

You're basically talking about creating all combinations or permutations (I can never remember which is which) of a series of digits so that's what you should research. I'd be shocked if there weren't a number of examples available.

Maybe somehting like this. You can use a bootstrap algorithm to shift the numbers randomly. As long as the string is small.

C#:
public class Test    {
public List<String> ShiftedNumbers = new List<string>();
public static Random Random = new Random();

public String TakeOne(int lower, int upper, String Content)
{
return Content.Substring((int)Random.Next(lower, upper),1);
}

public List<String> Start(String NumbersToShift)
{
bool found = false;
StringBuilder SB = new StringBuilder();
String Current = "";

int Faculty = GetFactorial(NumbersToShift.Length);

do
{
SB.Clear();
for (int i = 0; i <= NumbersToShift.Length - 1; i++)
{
Current = TakeOne(0, NumbersToShift.Length, NumbersToShift);

if (SB.ToString().IndexOf(Current) <= -1)
{
SB.Append(Current);
}
else if (SB.ToString().Length >= NumbersToShift.Length)
{
break;
}
else if (SB.ToString().IndexOf(Current) >= 0)
{
i = i - 1;
}

}

found = false;
for (int i = 0; i <= ShiftedNumbers.Count() - 1; i++)
{
if (ShiftedNumbers[i] == SB.ToString())
{
found = true;
break;
}
}

if (found == false)
{
}

} while (ShiftedNumbers.Count() < Faculty);

return ShiftedNumbers;

}

public int GetFactorial(int Length)
{
int R = 1;

for (int i = 1; i<= Length; i++)
{
R = R * i;
}

return R;

}

}

There are C# operators like << and >> . I have not tried them so far but they should have something to do with shifting chars or numbers.

Last edited:

Replies
11
Views
587
Replies
6
Views
211
Replies
0
Views
222
Replies
2
Views
190
Replies
8
Views
969