Thread: Re: [Dev-C++] Producing a endless list of strings.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: David M. <ci...@ya...> - 2003-07-31 03:34:30
|
Uh the way I was seeing it was that the recursion would
only go to a level
equal to the length if the string.
Ok, the idea was to create all the possible combinations
(up to 100
characters long) using all the avalible characters in the
ascii character
set from 32 (space) to 126 (~) inclusive. When we try to
increment '~' we
end up getting a space and we increment the next character
in the string and
applying the same overflow rule.
Here are some sections of the expected output:
gksdg
hksdg
iksdg
jksgd
kksgd
.....
|ksgd
}ksgd
~ksgd <-We have reached ~ so the next string will
have <space> and
we have to increment the next character.
lsgd <- Note that this is <space>lsgd
!lsgd
"lsgd
Things get interesting when this situation arises.
y~~~ju
z~~~ju
{~~~ju
|~~~ju
}~~~ju
~~~~ju
<sp><sp><sp><sp>ku <- <sp> = space
in this case we had 4 overflows to deal with
In case you are wondering I am looking for varible length
strings up to the
max (in this case 100).
I hope this makes things clearer. Also '++' works quite
well in incrementing
one character, my problem is with handling the overflow.
Signed
David Mcken
----- Original Message -----
From: "manilius" <man...@gm...>
To: "'Dev-C Mailing List'"
<dev...@li...>
Sent: Wednesday, July 30, 2003 4:54 PM
Subject: AW: [Dev-C++] Producing a endless list of strings.
> Hi,
>
> > Eventually I hope to use this to create strings at
least
> > 100 chars long (possibly 1000). Could someone tell me
if
> > 100 levels using recursion cause a stack overflow?
>
> Do I understand you correctly that you want to create a
list with every
> possible string of 100 or even 1000 characters?
> Even a list of all lower case strings with 10 letters
takes about 10^15
> bytes. You will definitely get a stack overflow :)
>
> But here is how you could do it:
>
> #include <iostream>
> #include <string>
> #include <vector>
> #include <stdlib.h>
>
> using namespace std;
>
> vector<char> CharacterTable;
>
> void CreateAllPossibleStrings(string String, int
RecursionLevel)
> {
> if(RecursionLevel > 0)
> {
> for(int i=0; i<CharacterTable.size(); i++)
>
>
CreateAllPossibleStrings(String+CharacterTable[i],RecursionLevel-1);
> }
> cout << String << endl;
> }
>
> int main(int argc, char *argv[])
> {
> // Init character table, only lower case letters in this
case
> for( int i=0; i<26; i++) CharacterTable.push_back('a'+i);
>
> // Create all strings, recursion depth is 2...try to
increase it :)
> CreateAllPossibleStrings("",2);
>
> system("PAUSE");
> return 0;
> }
>
> ciao...
> ..manilius
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET
sites including
> Data Reports, E-commerce, Portals, and Forums are
available now.
> Download today and enter to win an XBOX or Visual Studio
.NET.
>
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE:
http://www23.brinkster.com/noicys/devcpp/ub.htm
>
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
|
|
From: manilius <man...@gm...> - 2003-07-31 08:11:21
|
Hi
=20
> Ok, the idea was to create all the possible combinations
> (up to 100
> characters long) using all the avalible characters in the
> ascii character
> set from 32 (space) to 126 (~) inclusive. When we try to
> increment '~' we
> end up getting a space and we increment the next character
> in the string and
> applying the same overflow rule.
Okay, that would be one way to do it, but it does involve a lot of =
string
manipulation (check a character and change it) which is not needed with
recursion. Is there a special reason you want to use your "overflow
algorithm"?
If you want more characters with the recursion example I sent you, just =
add
them to the character table:
for( int i=3D0; i<92; i++) CharacterTable.push_back(' '+i);
should include all characters you want.
If you need zero-terminated strings, you can use the function c_str() of =
the
std::string class to create them.=20
But again: There is no way to create a list of all possible strings with =
the
length of 100. You have
(# of possible charcters)^length of the string=20
possibilities. This results in a huge number (try calculate 92^100 :)=20
ciao...
...manilius
|
|
From: David M. <ci...@ya...> - 2003-07-31 16:19:39
|
Cool, thanks for your help
Signed
David Mcken
--- manilius <man...@gm...> wrote:
>
> Hi
>
> > Ok, the idea was to create all the possible
> combinations
> > (up to 100
> > characters long) using all the avalible characters in
> the
> > ascii character
> > set from 32 (space) to 126 (~) inclusive. When we try
> to
> > increment '~' we
> > end up getting a space and we increment the next
> character
> > in the string and
> > applying the same overflow rule.
>
> Okay, that would be one way to do it, but it does involve
> a lot of string
> manipulation (check a character and change it) which is
> not needed with
> recursion. Is there a special reason you want to use your
> "overflow
> algorithm"?
>
> If you want more characters with the recursion example I
> sent you, just add
> them to the character table:
>
> for( int i=0; i<92; i++) CharacterTable.push_back(' '+i);
>
> should include all characters you want.
> If you need zero-terminated strings, you can use the
> function c_str() of the
> std::string class to create them.
>
>
> But again: There is no way to create a list of all
> possible strings with the
> length of 100. You have
>
> (# of possible charcters)^length of the string
>
> possibilities. This results in a huge number (try
> calculate 92^100 :)
>
> ciao...
> ...manilius
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET
> sites including
> Data Reports, E-commerce, Portals, and Forums are
> available now.
> Download today and enter to win an XBOX or Visual Studio
> .NET.
>
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
>
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
=====
Signed
David Mcken
Life Sucks
Live with it
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
|