I was reading this article: http://www.huffingtonpost.com/2015/05/2 ... 46332.html
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.
Solve Math Problem in MT
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Solve Math Problem in MT
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
-
- 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)
10 separate functions, (8 of which are functionally identical), each calling the next in the chain. Recursion without recursion.
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)]
}