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, Western Australia.) 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

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Experimenting with a "StringList" type for simpler handling of string arrays/lists Heimdall 18 1,263 12-19-2025, 12:51 PM
Last Post: Heimdall
  Sub not Reconizing Dim as String pmackay 18 1,477 10-16-2025, 03:32 PM
Last Post: pmackay
  for performance, what's the best variable type to use for boolean _TRUE & _FALSE ? madscijr 12 1,263 09-29-2025, 02:59 PM
Last Post: dakra137
  Illegal string-number conversion Herve 7 775 07-07-2025, 09:53 AM
Last Post: a740g
  need help printing a scaled string in a custom font to a 32-bit image madscijr 9 1,168 07-03-2025, 04:48 PM
Last Post: SMcNeill

Forum Jump:


Users browsing this thread: 1 Guest(s)