Subj : Re: Unique sets from {1..n} ? To : comp.programming From : Willem Date : Mon Jul 11 2005 09:18 am TC wrote: ) Willem wrote: )> TC wrote: )> ) Hi Willem )> ) )> ) I am aware of the pattern! It was just the algorithym that defeated me. )> ) And I had not thought of using the bit pattern to select the items. I'm )> ) currently using that approach: )> ) )> ) for k = 1 to n )> ) for j=1 to 32(or whatever) )> ) if bit j=1, add item #j to set #k )> )> The two variables (j and k) don't loop to the right amounts. )> This algorithm won't work as such. )> (Except for a very specific value for n, which I doubt you had in mind.) ) ) Um, the two variables /do/ loop to the right amounts and the algorithym ) will and does work exactly as shown (with a clarification noted below). In the original problems, you stated you had n items in the original set. That means that j should loop from 1 to n, but you're looping k from 1 to n. Here's what it *should* be: for k = 1 to 2^n for j = 1 to n if bit j=1, add item #j to set #k I see below that you changed the meaning of n. ) All it assumes is that the counter k is implemented as a 32-bit ) unsigned integer, and that n is constrained to the corresponding ) maximum value. Corrseponding to which maximum value ? 2^n, perhaps ? So n equals 2^n. You can't go around changing the meaning of variables without saying what you change them to (or even that you changed it at all) and then hope that people will somehow magically understand this. ) The only language missing from the algortithm, is to add the words: "of ) the binary implementation of the value k", after the words "if bit j". Wrong tree. What's missing is the initialisation of n to the proper value. SaSW, Willem -- Disclaimer: I am in no way responsible for any of the statements made in the above text. For all I know I might be drugged or something.. No I'm not paranoid. You all think I'm paranoid, don't you ! #EOT .