TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: All
from: Mike Ruskai
date: 1998-11-21 23:00:14
subject: Numeric algorithm desired.

I'd like to know the most efficient way to do iterate through all 
combinations of X number of the same Y objects.

For example, assume 20000 objects.  I'd like to iterate through every 
non-duplicate combination of 5 objects from that collection.  By 
non-duplicate, I mean that 1/2/3/4/5 and 1/3/5/4/2 are the same, since they 
contain the same objects, but in a different order.

As near as I can tell, I'm looking at 10E20 combinations with 20000 objects 
and 5 at a time.  I know it will take a while, but I'd like to know how to 
do it, with a variable amount of X and Y (where the above example has X as 
5, and Y as 20000).

If a more specific example would help, let me explain what I'm doing.

I've got a utility for the BBS door game Tradewars 2002, which locates 
clusters of sectors (it's a space-oriented game) that are connected to each 
other, but isolated from the rest of the universe.  The term used is 
bubbles, and currently I've got the program written to only handle bubbles 
with a single entrance.  I'd like to expand that to handle more than one 
entrance (that is, more than one way to get in and out of the bubble from 
the universe at large).  

In order to do that, I need to iterate through all non-duplicate 
combinations of X sectors at a time, where X is the number of entrances.

I've got it working now by simply having a 5-level loop, but that approach 
gives me an extra 3.2E21 loop iterations for a 5-entrance bubble with 20000 
sectors.  

A plain-English alogorithm would be desirable.

Mike Ruskai
thanny{at}home.com


... If at first you don't succeed, you must be using Windows.
--- Renegade v05-11 Exp
* Origin: The Licking Factory, OS/2 in NJ! (732)815-3146 (1:107/634)
SEEN-BY: 396/1 632/0 371 633/260 267 270 371 635/444 506 728 639/252 670/218
@PATH: 107/634 451 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.