Hey.
I am working on a project to make a code iteration generator. So, you’d input a string of, say, “xxy” and the code will give you all the possible combinations of that string. So, “yxx, xyx, xxy”
I have worked out this so far:
The string, in this case is “xxy.”
n = possible combinations
i = string length
∂i = number of different letters in the string / i
Therefore, n = i^(∂i) different possibilities?
(The above is now incorrect)
I did some manual combination checking, and when there are 3 different letters and three spaces available in the string, there would be 3^2 - 4 = 5 different possibilities.
( four repetitions in my working )
My working was:
x o y | [o x y] | y x o
o x y | [x o y] | [x y o]
o y x | x y o | [x o y]
so, a formula for finding the total combinations would be great as well… cuz mine was wrong.
Now, what I need is a formula to apply within a for( ) loop which would generate the possibilities, assuming I got the ∂i stuff right…
So, for every run through the loop, it’d apply the formula, and add a letter to the output string based on the combinations available?
My code thus far is:
#pragma strict
var inputCode : String;
var output : String;
private var running : boolean;
function Start()
{
inputCode = "";
output = "";
running = false;
}
function OnGUI()
{
GUI.BeginGroup(Rect(10,10,1000,1000));
if(!running)
{
inputCode = GUI.TextArea(Rect(0,0,200,25), inputCode, 500);
}
else
{
GUI.Label(Rect(0,0,200,25),"Generating...");
}
if((GUI.Button(Rect(0,30,200,25), "Generate")) && (!running))
{
Iterate(inputCode);
}
GUI.Label(Rect(0,60,2000,25), output);
GUI.EndGroup();
}
function Iterate(ic : String)
{
running = true;
output = "";
// find ∂i
for(var i = 0; i < ic.Length; i++)
{
output += ic*; // replace with formula?*
-
}*
-
running = false;*
}
I am at a loss with this, and would be amazing if someone could help.
thank you
-F