## Solve Math Problem in MT

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Deity
Posts: 8603
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

### Solve Math Problem in MT

And I was wondering how I would check each possible permutations. There are a couple of algorithms out there in other languages, but since we're stuck with size 1000 loops how would you do it in MT. A recursive call comes to mind, but I think there is a limit to that as well.

For bonus points, do it in numerical order from low to high, ie 1,2,3,4,5,6,7,8,9 to 9,8,7,6,5,4,3,2,1. BTW, there are 9! combinations for 362880 permutations.

Akodo Makama
Giant
Posts: 249
Joined: Mon Apr 20, 2009 9:31 pm

### Re: Solve Math Problem in MT

Recursion can always be traded for memory (especially of you know the maximum recursion depth)

Code: Select all

``PrepLists  [constructedStringList1 = ""]  [possiblePartsList1 = ""]  [for(index,1,9): possiblePartsList1 = listAppend(possiblePartsList1, index]  [PermutateString1()]PermutateString* (* = 1-8, ^ = *+1)  [end = listCount(possiblePartsList*) - 1]  [for (index, 0, end), code:  {    [constructedList^ = listAppend(constructedStringList*, listIndex(possiblePartsList*, index))]    [possiblePartsList^ = listDelete(possiblePartsList*, index]    [PermutateString^()]  }PermutataString9  [end = listCount(possiblePartsList9) - 1]  [for (index, 0, end), code:  {    [constructedListFinal = listAppend(constructedStringList9, listIndex(possiblePartsList9, index))]    [checkMathProblem(constructedListFinal)]  } ``

10 separate functions, (8 of which are functionally identical), each calling the next in the chain. Recursion without recursion.