Re: FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)
From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 09/28/04
- Next message: CJ Taylor: "Re: ISenslogon"
- Previous message: William Apple: "Error using object type array."
- In reply to: Jon Skeet [C# MVP]: "Re: FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)"
- Next in thread: Jon Skeet [C# MVP]: "Re: FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)"
- Reply: Jon Skeet [C# MVP]: "Re: FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)"
- Reply: Cor Ligthert: "Re: FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: CJ Taylor: "Re: ISenslogon"
- Previous message: William Apple: "Error using object type array."
- In reply to: Jon Skeet [C# MVP]: "Re: FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)"
- Next in thread: Jon Skeet [C# MVP]: "Re: FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)"
- Reply: Jon Skeet [C# MVP]: "Re: FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)"
- Reply: Cor Ligthert: "Re: FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|