Subj : Re: how to generate a sequence? To : comp.programming From : Thad Smith Date : Thu Sep 08 2005 04:36 pm Neo wrote: > >> I have problem, I want to generate all possible (unique) combinations of > >> the > >> following sequence: > >> > >> > >> 123456789 > >> 213456789 > >> 312456789 > >> 321456789 What you describe is all possible permutations, not combinations. > Well, for 4-5 symbols it was quick enough, but to ma surprise when I > increase symbols to 9 damm.... it took 01 min 28.0954414 sec to exec and > it process's mem usage was 216 MB !!!!!!!!!!!!!!!!!!!!! That's because you kept each generated permutation in memory. > BUT THIS IS REALY REALYYYYY CRAZY... This not absolutely not > acceptable!!!!!!! > Think about this.. if this sequence is to be generated in an embedded system > where maximum ram available is 32 KB only!!!!!!!!!!! The questions to ask are: 1. Why do you want to generate all permutations? 2. What do you do with a permutation once generated? 3. How long do you need to keep each permutation in memory? Typically, you don't need all permutations at once. Thad .