🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.pascal.ansi-iso
5 messages
5 total messages Started by Andrew Mon, 06 Mar 2000 00:00
all possible combinations
#3
Author: Andrew
Date: Mon, 06 Mar 2000 00:00
30 lines
1548 bytes
Anyone have any pascal code for all possible combinations of a set?

So if we start with '1','2','3' the possible combinations are:

1
2
3
1 2
1 3
2 3
1 2 3

This seems to be a FAQ on discussion groups in general, but
I could not find anything in Pascal.  I found some C++ code
in another group but it looks like bad pseudocode to me -- I'm
kindof a pascal diehard.  But I'm not a big programmer
and this problem has my brain in knots right now.

A response in any flavor of pascal would be much appreciated.

TIA,

  Andrew
--
Andrew
noymer@my-deja.com


Sent via Deja.com http://www.deja.com/
Before you buy.
Re: all possible combinations
#4
Author: Bob Schor
Date: Mon, 06 Mar 2000 00:00
43 lines
2125 bytes
Here's one way to think about it, and possibly come up with an
algorithm.  First, how many combinations are there of three things?
[You listed 7].  How about 2 things?  One thing?  Is the pattern
obvious?  Next, given N things, each "thing"  is either a member of a
particular combination or it is not, i.e. there are two possible
"states" for each of the N things.  You now only need to enumerate (i.e.
count) them.  If you can figure out the "natural" mapping between these
N things and numbers, your problem will be mostly solved.

Bob Schor
Pascal Enthusiast

Andrew wrote:

> Anyone have any pascal code for all possible combinations of a set?
>
> So if we start with '1','2','3' the possible combinations are:
>
> 1
> 2
> 3
> 1 2
> 1 3
> 2 3
> 1 2 3
>
> This seems to be a FAQ on discussion groups in general, but
> I could not find anything in Pascal.  I found some C++ code
> in another group but it looks like bad pseudocode to me -- I'm
> kindof a pascal diehard.  But I'm not a big programmer
> and this problem has my brain in knots right now.
>
> A response in any flavor of pascal would be much appreciated.
>
> TIA,
>
>   Andrew
> --
> Andrew
> noymer@my-deja.com
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
Re: all possible combinations
#5
Author: Wolf Behrenhoff
Date: Mon, 06 Mar 2000 00:00
47 lines
1893 bytes
Andrew wrote:
> Anyone have any pascal code for all possible combinations of a set?
> 
> So if we start with '1','2','3' the possible combinations are:
> 
> 1
> 2
> 3
> 1 2
> 1 3
> 2 3
> 1 2 3


number of combinations

= number of combinations 1 of 3
  + number of combinations 2 of 3
  + number of combinations 3 of 3

    3       3       3
= (   ) + (   ) + (   )
    1       2       3

= 3+3+1

= 7
       a
with (   ) = a! / (b! (b-a)!)
       b

I think you missed the combination 0 of 3 in your list. Unless this
was                             3
intended, you have to add (   ) = 1. Then the result would be 8.
                            0

                         n
                        ---
                        \     n
generalized: num of c =  >  (   )  for a set with n elements.
                        /     k
                        ---
                        k=0

Translating this into Pascal is up to you.

Wolf
Re: all possible combinations
#6
Author: Adam Anderson
Date: Tue, 07 Mar 2000 00:00
45 lines
2158 bytes
Ok I answered a similar question to this a few weeks ago.

To generate all possible combinations for a given number of symbols, you
use the quantity of symbols as a new base in a number system, 10 is the
base in decimal, 16 is the base in hexidecimal. Once you know the base
you can then use a simple mathematical process to convert an
incrementing decimal number to the new base.

Use lookup tables for the conversion process. For information on the
conversion process look at Decimal to Hex Conversion.

Regards
Adam Anderson

Andrew wrote:

> Anyone have any pascal code for all possible combinations of a set?
>
> So if we start with '1','2','3' the possible combinations are:
>
> 1
> 2
> 3
> 1 2
> 1 3
> 2 3
> 1 2 3
>
> This seems to be a FAQ on discussion groups in general, but
> I could not find anything in Pascal.  I found some C++ code
> in another group but it looks like bad pseudocode to me -- I'm
> kindof a pascal diehard.  But I'm not a big programmer
> and this problem has my brain in knots right now.
>
> A response in any flavor of pascal would be much appreciated.
>
> TIA,
>
>   Andrew
> --
> Andrew
> noymer@my-deja.com
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
Re: all possible combinations
#7
Author: Andrew
Date: Tue, 07 Mar 2000 00:00
21 lines
1523 bytes
In article <89v8r3$vag$1@nnrp1.deja.com>,
  I wrote:
> Anyone have any pascal code for all possible combinations of a set?

Thanks to all those who replied.

I forgot the important maxim of set theory: the empty set is
a subset of all sets.  So there are 2^N subsets of N elements.

I have a recursive algorithm now that uses enumeration of
binary numbers to get all possible subsets.  Far too clever for
me to have figured it out.  But I undertand it now that I see it.

Thanks again.

- Andrew
noymer@my-deja.com


Sent via Deja.com http://www.deja.com/
Before you buy.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads