Home All Groups Group Topic Archive Search About
Author
25 May 2005 12:07 PM
Peter
Dear All

I need to program a kind of "algorithm" in VB6 that does the following:
I have upto 10 different strings(in string array), each with different
length and content which should be concatenated to several result strings
that are limited to a certain length.
Example1:
string1="AAAA", string2="BB", string3="CCCCC" string4="DDDDDD" string5="E"
string6="FFFFFFF"etc.
max size of all result strings is 8, the size of the result
Result stringA="BBDDDDDD" 'exacly 8 chars, best match
Result stringB="FFFFFFFE" 'eaxcly 8chars, again best match
Result stringC="CCCCC"    'AAAA+CCCCC not allowed because total length would
be >8
Result stringD="AAAA"

Example2: string1="A" string2="B" string3="C" string4="D" string5="EEE"
string6="FF" string7="GGG"
max size of all result strings is 4
Result stringA="AEEE"
Result stringB="BGGG"
Result stringC="CDFF"

The goal should be to get as less result strings as possible therefore the
better the concatenation reaches the max. limit the fewer result strings
should be required.
It does not matter what strings will be put in what result string and it
does not matter what order the individual strings have inside the
resultstrings.
Could anyone please help me how to program such an algorithm in VB6?
Do I need to do all possible concatenations and remember the length of each?
But how do I proceed then?
Thanks for any hints on this.
Regards
Peter

Author
25 May 2005 12:56 PM
Larry Serflaten
"Peter" <pete***@myrealbox.com> wrote
> Dear All
>
> I need to program a kind of "algorithm" in VB6 that does the following:

> The goal should be to get as less result strings as possible therefore the
> better the concatenation reaches the max. limit the fewer result strings
> should be required.

> Do I need to do all possible concatenations and remember the length of each?
> But how do I proceed then?

To help you understand the process, do it yourself several times.  Cut
out some pieces of paper to various lengths to represent various string
sizes, then pick some number of them, and a result size, and proceed
to group them to get the desired result.

Do that several times for various groups and result sizes.  Do it until you
feel you can pick any grouping and desired result size, and build the
least number of strings from start to finish, with little to no second guessing
yourself.

When you can take any random grouping and directly put them in order,
the way they need to go, then you have discovered an algorithm,  What you
do next is look at and analyze the steps you take to get the job done, and
finally, you convert those steps to code.

In short, work it out with pen and paper (or with pieces of paper) so that
you get a good feel for what needs to be done.  When you can solve the
problem yourself in a straight forward manner, you will be in a better position
to tell the computer how to solve that same problem....

LFS
Author
25 May 2005 1:48 PM
Peter
Hi
Thanks for your answer!!
I will do what you suggested.
Regards
Peter
Show quoteHide quote
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:OTiOkiSYFHA.228@TK2MSFTNGP12.phx.gbl...
>
> "Peter" <pete***@myrealbox.com> wrote
> > Dear All
> >
> > I need to program a kind of "algorithm" in VB6 that does the following:
>
> > The goal should be to get as less result strings as possible therefore
the
> > better the concatenation reaches the max. limit the fewer result strings
> > should be required.
>
> > Do I need to do all possible concatenations and remember the length of
each?
> > But how do I proceed then?
>
> To help you understand the process, do it yourself several times.  Cut
> out some pieces of paper to various lengths to represent various string
> sizes, then pick some number of them, and a result size, and proceed
> to group them to get the desired result.
>
> Do that several times for various groups and result sizes.  Do it until
you
> feel you can pick any grouping and desired result size, and build the
> least number of strings from start to finish, with little to no second
guessing
> yourself.
>
> When you can take any random grouping and directly put them in order,
> the way they need to go, then you have discovered an algorithm,  What you
> do next is look at and analyze the steps you take to get the job done, and
> finally, you convert those steps to code.
>
> In short, work it out with pen and paper (or with pieces of paper) so that
> you get a good feel for what needs to be done.  When you can solve the
> problem yourself in a straight forward manner, you will be in a better
position
> to tell the computer how to solve that same problem....
>
> LFS