# Finding correct combination of functions

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,S,S}
F2[S]={-S,-S,S}
F3[S]={-S,-S,-S}


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

• Honestly I find your explanation a bit confusing. Dec 21, 2015 at 16:00
• Tuples[{f1, f2, f3}, k] gives you all possible ways these three functions can be applied k times. Apply Composition to each list you got from Tuples 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. Dec 21, 2015 at 16:14
• Here's an example to demonistrate, with symbols only this time: Table[Apply[Composition][f][s], {f, Tuples[{f1, f2, f3}, 2]}]. You can break form Table or Map with Throw. Dec 21, 2015 at 16:15