Re: FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 09/28/04


Date: Tue, 28 Sep 2004 08:15:11 -0500

Jon,
Just out of curiosity, would you consider a StringBuilder "better" then
simply defining an array of 17 Char that you passed to New String?

As you are continually replacing a single char in the "buffer".

Something like:

    Private Shared Sub FindMatch(ByVal chars() As Char, ByVal index As
Integer)
        If index = chars.Length Then
            Debug.WriteLine(New String(chars))
        Else
            FindMatch(chars, index, AscW(" "c))
            For charCode As Integer = AscW("a") To AscW("z")
                FindMatch(chars, index, charcode)
            Next
            For charCode As Integer = AscW("A") To AscW("Z")
                FindMatch(chars, index, charcode)
            Next
        End If
    End Sub

    Private Shared Sub FindMatch(ByVal chars() As Char, ByVal index As
Integer, ByVal charCode As Integer)
        chars(index) = ChrW(charCode)
        FindMatch(chars, index + 1)
    End Sub

    Public Shared Sub Main()

        Dim chars(16) As Char

        FindMatch(chars, 0)

    End Sub

I would consider inlining FindMatch(char(), integer, integer) for
performance reasons...

Just curious
Jay

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1bc32f4a816c9c7a98b527@msnews.microsoft.com...
> DraguVaso <pietercoucke@hotmail.com> wrote:
>> I need to find the FASTEST way to get a string in a Loop, that goes from
>> "a"
>> to "ZZZZZZZZZZZZZZZZZ".
>
> Even using just 17 characters (unlike the last one you've given below)
> there are a ridiculous number of combinations. You just *won't* be able
> to test every one of them. With 53 symbols (a-z, A-Z, space) you get
> 205442259656281392806087233013 combinations.
>
> Assuming you could process 100 *billion* of them every second, it would
> still take you 65145313183 years to go through them all. Do you really
> have that much time?
>
> Now, as for speeding up what you've got: using a StringBuilder instead
> of repeated string concatenation would be a good start. Alternatively
> you could use a char array. (I haven't checked your actual algorithm
> for correctness, btw.)
>
> I note that you're using 52^30 as the number of possible combinations,
> which I don't quite understand if you're including space, but even so,
> that makes the length of time taken even greater.
>
> Suppose you have a million computers *each* processing 100 billion
> combinations a second, to get through 52^30 combinations I suspect
> you'd have to wait until way after the sun had gone cold to see the
> end.
>
> In other words: you'll need to find a different way of approaching your
> problem...
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



Relevant Pages

  • Re: Deserializing an array
    ... a tutorial on serializing and deserializing arrays at. ... > Conversation: Deserializing an array ... > Private Sub btnImport_Click(ByVal sender As System.Object, ... > Protected Sub ReadJudgesTable(ByVal filename As String) ...
    (microsoft.public.dotnet.xml)
  • Re: Declaring arrays
    ... >>Dim aAs String, bAs Double ... >>End Sub ... If b were declared as an array of variants, ... assign ranges to arrays of particular types. ...
    (microsoft.public.excel.programming)
  • Re: is there an alternative to strstr
    ... >> To exploit this fact, you need a different data format, a plain string is ... > Ok I have put the email ids in a sorted array. ... However you can use an array of char pointers and use ... int cmp(const void *v1, const void *v2); ...
    (comp.lang.c)
  • Re: Pointers on string members of structure
    ... because this just points memstr to a fixed string and it is undefined to ... char memstrA; ... string array directly like this and how? ... struct or if the struct member points to the array. ...
    (microsoft.public.vc.language)
  • Re: Best way to INSERT
    ... Private mlngCurrentIndex As Long ... Public Property Get StringValue() As String ... Public Sub AddText ... 'Class to encapsulate array generation of strings. ...
    (microsoft.public.inetserver.asp.general)