Mail Archives: djgpp/1999/10/06/18:38:24
umaveci0 wrote:
>
> I have an assignment in which I must write a program which solves a
> letter 'Jumble'. User types in some letters (rivfey, for example), all
> permutations (different combinations) of the letters are put into a
> vector ( vector<string> ) and each permutation is compared to another
> vector of strings containing about 20,000 words (a dictionary) to get
> the answer (verify). Problem is I run out of memory. Both
> vector<string> 's are big and solving a 6 letter Jumble causes the
> program to crash (5 is okay). I am referencing the vectors. How do I
> allow the program to use more memory?
>
> I'm using DJGPP in WIN95 and have 64Mb of RAM.
>
> Thanks.
Hmmm . . . Why not rewrite your program to use less memory?
You don't seem to have any trouble generating your vector of
permutations. That's actually kind of tricky, getting all the loops
right. But remember that the size of this vector will get HUGE very
quickly -- it increases as n! the number of letters.
So rather than storing the entire vector of permutations, why not just
store each one in turn? This will require a single string instead of a
vector<string> with n! elements. If you don't get a match, you generate
your next permutation.
If the assignment is worded such that you must use a vector for your
permutations, as opposed to just the dictionary, then decide in advance
how large you will allow your vector to grow. Then divide your vector
of permutations accordingly.
Charles
- Raw text -