How to reorder string variable x factorial different ways? - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: How to reorder string variable x factorial different ways? (/showthread.php?tid=2619) Pages:
1
2
|
How to reorder string variable x factorial different ways? - Circlotron - 04-24-2024 Say I have a string variable abcd$. The letters in the variable can be arranged 4 factorial or 4x3x2x1 different ways. How can I produce every combination? Find Len(abcd$) then a for/next loop Len factorial times, but what inside the loop? I'm at a loss here. RE: How to reorder string variable x factorial different ways? - Kernelpanic - 04-24-2024 (04-24-2024, 11:14 AM)Circlotron Wrote: Say I have a string variable abcd$. The letters in the variable can be arranged 4 factorial or 4x3x2x1 different ways. How can I produce every combination? Find Len(abcd$) then a for/next loop Len factorial times, but what inside the loop? I'm at a loss here.This is the calculation of the factorial: n! Code: (Select All)
Oder in Julia: RE: How to reorder string variable x factorial different ways? - Circlotron - 04-24-2024 Thanks for that. In the meantime I realised I was asking the wrong question. I'll start a new thread. RE: How to reorder string variable x factorial different ways? - bplus - 04-24-2024 maybe you want every permutation, not combination as there are 4! permutations to abcd letters. RE: How to reorder string variable x factorial different ways? - SMcNeill - 04-24-2024 Code: (Select All)
FactorIt above generates a list of values, removing duplicates for you. For example, "goo" has two "o"s, so it can only generate "goo", "ogo", "oog", and a few of those in duplicate which we don't count. RE: How to reorder string variable x factorial different ways? - Pete - 04-25-2024 I tried running the string "THIS" in this FreeBASIC permutation algorithm, but it got stuck in an endless loop... Code: (Select All)
I'm thinking about emailing it to Clippy, as a screen saver. Pete RE: How to reorder string variable x factorial different ways? - PhilOfPerth - 04-25-2024 (04-24-2024, 11:14 AM)Circlotron Wrote: Say I have a string variable abcd$. The letters in the variable can be arranged 4 factorial or 4x3x2x1 different ways. How can I produce every combination? Find Len(abcd$) then a for/next loop Len factorial times, but what inside the loop? I'm at a loss here. I' m currently working on a similar problem for one of my games (hope it's not the same game!) so I'll be interested to see what comes up from the gurus here. (04-25-2024, 02:13 AM)Pete Wrote: I tried running the string "THIS" in this FreeBASIC permutation algorithm, but it got stuck in an endless loop... Wow, wonder why that happens! RE: How to reorder string variable x factorial different ways? - PhilOfPerth - 04-25-2024 (04-24-2024, 07:41 PM)SMcNeill Wrote: Ahah! That's a (reasonably) simple solution to a problem I'm wrestling with at the moment! I had written a factorial-ising routine, but it was way too bulky and slow to be useful. I'll try to adapt this into my language ("dumb it down") and use it! Edit: This worked when I used alpha chars, which is what I want) to do), but when I used anything longer than 7 characters, it gave no result. Edit2: I was able to get results when I added this before the last Next, and remove the Print wordlist$(i) Print wordlist(k);" "; It's still very slow for more than 7 chars, but that may be enough (for mine, anyway). 87 sec for 8 characters. RE: How to reorder string variable x factorial different ways? - bplus - 04-26-2024 Quote:Edit: This worked when I used alpha chars, which is what I want) to do), but when I used anything longer than 7 characters, it gave no result. these are permutations, there are n! for n elements N! = 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, .... that sequence expands faster than any x^n ie expedentially plus! you propably didn't get results because you didn't wait long enough plus real easy to go beyond the limits of the type fairly quickly. that routine steve provided i think was better than what i had, except maybe the non recursive one? i filed the data for 10 letters or digits so i could use a substitution technique for 10 of anything without recalculating permutaions of 10 things because it takes so long. RE: How to reorder string variable x factorial different ways? - PhilOfPerth - 04-26-2024 At the risk of hijacking Circlotron's post further, thanks @bplus. I was aware of the permutatins thing and its associated problem with expansion, but couldn't see a way around it. Not sure what you meant in your last line, about filing the data... could you elaborate a little? It sounds interesting. |