Brute-Force
Brute-Force algorithm (a.k.a brute-force search, exhaustive search) is a very general problem-solving technique that consists of systematically enumerating all possible candidates for the solution and checking whether each candidate satisfies the problem's statement.
Public Delegate Function BruteForceTest(ByRef testChars As Char()) As Boolean
Public Shared Function BruteForce(testChars As String, startLength As Integer, endLength As Integer, testCallback As BruteForceTest) As Boolean
For len As Integer = startLength To endLength
Dim chars As Char() = New Char(len - 1) {}
For i As Integer = 0 To len - 1
chars(i) = testChars(0)
Next
If testCallback(chars) Then
Return True
End If
For i1 As Integer = len - 1 To -1 + 1 Step -1
Dim i2 As Integer = 0
For i2 = testChars.IndexOf(chars(i1)) + 1 To testChars.Length - 1
chars(i1) = testChars(i2)
If testCallback(chars) Then
Return True
End If
For i3 As Integer = i1 + 1 To len - 1
If chars(i3) <> testChars(testChars.Length - 1) Then
i1 = len
GoTo outerBreak
End If
Next
Next
outerBreak:
If i2 = testChars.Length Then
chars(i1) = testChars(0)
End If
Next
Next
Return False
End Function
Example
Dim testCallback As BruteForceTest = Function(ByRef testChars As Char()) As Boolean
Dim str = New String(testChars)
Return (str = "bbc")
End Function
Dim result As Boolean = BruteForce("abcde", 1, 5, testCallback)
Output
True