Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to reorder string variable x factorial different ways?
#8
(04-24-2024, 07:41 PM)SMcNeill Wrote:
Code: (Select All)
ReDim Shared WordList(0) As String
FactorIt "1234", ""
For i = 1 To UBound(WordList)
    Print WordList(i),
Next

Sub FactorIt (word$, seed$)
    For i = 1 To Len(word$)
        seed1$ = seed$ + Mid$(word$, i, 1)
        w$ = Left$(word$, i - 1) + Mid$(word$, i + 1)
        For k = 1 To UBound(WordList)
            If WordList(k) = seed1$ + w$ Then Exit For
        Next
        If k > UBound(WordList) Then
            ReDim _Preserve WordList(k) As String
            WordList(k) = seed1$ + w$
        End If
        FactorIt w$, seed1$
    Next
End Sub

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.

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.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply


Messages In This Thread
RE: How to reorder string variable x factorial different ways? - by PhilOfPerth - 04-25-2024, 11:19 PM



Users browsing this thread: 3 Guest(s)