Long time no hear.
I have a seemingly simple problem that I just can't get my head around how to script it.
I have a series of letters that I need to cycle through and get all of the permutations of it, and I just can't seem to get the right output.
I have shortened the lists for ease...
"B,A,P,Z,P,I,S,S,W"
"BI,AP,U,ZO,PA,IN,SC,SC,WO"
"BILT,APRI,P,ZOMB,PARA,SI,CRE,CRE,WO"
And I want get an output something like this:
BAP, BAZ, BAO, BAM, BAB, BAP, etc.
BPP, BPZ, BPO, BPM, etc.
BUA, BUP, BUR, BUI, BUZ, BUO, BUM, etc.
The process is this: take 1 item from the first list, then ignore the corresponding item in the other lists (item 1 in list 1, means ignore item 1 in all other lists). Take item 2 of list 2 and take the first character and ignore item 1 and 2 of list 3. Take item 3 of list 3 and take the first character, then the second character, then the third and fourth, then go back up one level, take character 2 of item 2 of list 2, and repeat with item 3 of list 3, etc.
Confusing, I know. It's brute force solving a game where you have a word list and need to write them out, so when you have used a word, you can't use it again. Then a certain letter from each word spells out another word. Literally 1000's of possibilities, so I thought an app that could output all of them could easily be scanned for the right answer.
The way I have been tackling it is to pick an item in list 1, then delete that item in all other lists, leaving me with one less item in all other lists, then picking an item of list 2, and deleting that item in all other lists, leaving it with less items. Eventually there will be one item in the last list. In the nested loops, the lists should be reinstated, but they aren't...
Here's what I have so far, but it's only cycling once...
Code: Select all
on mousedown
   put "B,A,P,Z,P,I,S,S,W" into wordList1
   put "BI,AP,U,ZO,PA,IN,SC,SC,WO" into wordList2
   put "BILT,APRI,P,ZOMB,PARA,SI,CRE,CRE,WO" into wordList3
   repeat with a = 1 to the number of items of wordList1
      put character 1 of item a of WordList1 into character1
      delete item a of WordList2
      delete item a of WordList3
      repeat with b = 1 to the number of items of WordList2
         repeat with z = 1 to the number of characters of item b of WordList2
            put character z of item b of WordList2 into character2
            delete item b of WordList3
            repeat with c = 1 to the number of items of WordList3
               repeat with y = 1 to the number of characters of item c of WordList3
                  put character y of item c of WordList3 into character3
                  put character1 & character2 & character3 into outputWord
                                                   put cr & outputWord after fld "Output"
                                                
                                             end repeat
                                          end repeat
                                       end repeat
                                    end repeat
                                 end repeat
 end mousedown
Any thoughts om how to tackle the problem? I hope that's not too confusing, I can keep explaining if needed.
XdM


 ) I was tossing and turning sure that there was something 'a bit odd' about your script.
 ) I was tossing and turning sure that there was something 'a bit odd' about your script.