Brute Force Loop

General FreeBASIC programming questions.
Post Reply
BobPaw
Posts: 41
Joined: Dec 13, 2014 2:03
Location: Texas, USA

Brute Force Loop

Post by BobPaw »

I have tried to make a brute force loop that will go through all symbols or letters and PRINT them, here is my attempt:

Code: Select all

Dim As String buffer
Dim As Integer a
Do
    a += 1
    For b As Integer = 1 To a
        buffer = ""
        For i As Integer = 32 To 126
            Cls
            buffer &= chr(i)
            Print "Folder: " & buffer
            Sleep 100, 1
        Next
    Next
Loop
'32 - 126
integer
Posts: 408
Joined: Feb 01, 2007 16:54
Location: usa

Re: Brute Force Loop

Post by integer »

BobPaw wrote:I have tried to make a brute force loop that will go through all symbols or letters and PRINT them, here is my attempt:

Code: Select all

Dim As String buffer
Dim As Integer a
Do
    a += 1
    For b As Integer = 1 To a
        buffer = ""
        For i As Integer = 32 To 126
            Cls
            buffer &= chr(i)
            Print "Folder: " & buffer
            Sleep 100, 1
        Next
    Next
Loop
'32 - 126
NOT A CRITICISM.
I'm confused as to what your code is intended to do after several thousand loops.
What is the purpose of the "DO...LOOP"
What is supposed to happen when a> 10 or 100 or 1 million ?
I do not understand how you are supposed to exit the Do...Loop

What is the reason for b = 1 to a ?
You are not saving the previous buffer contents.
b = 1 to 1 : b= 1 to 2 : b = 1 to 3 ...

Since you are not using the "buffer" for anything else,
why reset it at the end of the inner loop?

I'm not indicating anything is wrong with the above program or what you are trying to do.
What I am wanting to know is what are you trying to do?
A few explanations would help.
Simply stated: I do not understand why you want to repeat the process so many times?
Is this part of a timing procedure?

Code: Select all

        Dim As String buffer = ""
        For i As Integer = 32 To 126
            buffer &= chr(i)
        next i
        Print "Folder: " & buffer
        Sleep
BobPaw
Posts: 41
Joined: Dec 13, 2014 2:03
Location: Texas, USA

Re: Brute Force Loop

Post by BobPaw »

I understand what you mean, I was extremely confused at first.
It needs to go through the loop because after going through 1 set, it needs to go through 2 characters.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Brute Force Loop

Post by counting_pine »

Perhaps you are trying to create a program that creates every possible string of printable characters, starting at length 1, and continuing on ad infinitum?
The first thing you should know is that, beyond around 4 or 5 characters, creating all the possibilities will take a very long time.
When your code works correctly, everything in the loop body will need to have a time complexity of O(95^n), where n is the length of the string (i.e. 'a'). This is exponential time. Two simple loops nested will only ever be O(n^2) (polynomial time), which will fall very short, so the solution will necessarily be more complex than simply nesting For loops.
Post Reply