I am trying to write code where I have an array $S$ or numbers in any order [5,4,2,1,....]
Then I have a specific set of functions that I can write. F1,F2,
.....
I also have a set of arrays that would be a solution if the array looked like it
I want to write code specifically that takes the array and tries F1[S]
then tries F2[S]
then F3[S]
then try F1[F1[S]]
and keep trying growing combinations until it finds one in the solution set then it can print out the combination of functions that found the solution
The problem I am actually working on is the burnt pancake problem.
Where an array could be 3 long and be the three number in any order. Then it would try 3 functions
F1[S]={-S[1],S[2],S[3]}
F2[S]={-S[2],-S[1],S[3]}
F3[S]={-S[3],-S[2],-S[1]}
I have no problem writing the functions whenever I want to try a new size stack but my goal is to find the optimal solution Then I want to know what functions in what order would resolve the array so it would be contained in a set of arrays SS
To solve the cases of 1-3 I just used a program I wrote that tries every function set but it is 100 lines long and doesn't stop trying when it finds a solution. I can post that for reference if it is at all helpful. Thanks
Tuples[{f1, f2, f3}, k]
gives you all possible ways these three functions can be appliedk
times.Apply
Composition
to each list you got fromTuples
to get the final transformation function you can use with an array. This is of course an inefficient brute-force method, but according to my reading that is what you were asking about. $\endgroup$Table[Apply[Composition][f][s], {f, Tuples[{f1, f2, f3}, 2]}]
. You can break formTable
orMap
withThrow
. $\endgroup$