04-25-2024, 11:10 PM
(This post was last modified: 04-25-2024, 11:13 PM by PhilOfPerth.)
(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...
Code: (Select All)Print "Find the permutations of the word: THIS."
a$ = "THIS"
Sleep 5
Do
a = (Rnd * 3 Mod 4) * 365 / 4 ^ 7 + 4
b = (Rnd * 3 Mod 4) * 365 / 4 ^ 7 + 2
c = (Rnd * 3 Mod 4) * 365 / 4 ^ 7 + 3
d = (Rnd * 3 Mod 4) * 365 / 4 ^ 7 + 1
Print Mid$(a$, a, 1) + Mid$(a$, b, 1) + Mid$(a$, c, 1) + Mid$(a$, d, 1); " ";
_Delay .02
Loop Until perm = 24
I'm thinking about emailing it to Clippy, as a screen saver.
Pete
Wow, wonder why that happens!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/