Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.idl-pvwave

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 07-13-2012, 08:51 PM
antar3s86@gmail.com
Guest
 
Posts: n/a
Default Fastest way to list combinations

Hi

I have to solve a problem which includes listing all possible combinations to form a triplet for a given number of objects.

Say you have the objects:
a,b,c,d,e, so in total 5 which gives you 5!/(2!*3!) = 10 possibilities to list them without any doubles:

abc
abd
abe
acd
ace
ade
bcd
bce
bde
cde

I have solved this problem for any number (well up to some computer limit anyway) in three FOR loops but for large numbers this is rather small...

can you think of a better way than using loops to list all these possibilites?

thanks!!

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 07-13-2012, 09:01 PM
antar3s86@gmail.com
Guest
 
Posts: n/a
Default Re: Fastest way to list combinations

On Friday, July 13, 2012 10:51:41 PM UTC+2, (unknown) wrote:
> Hi
>
> I have to solve a problem which includes listing all possible combinations to form a triplet for a given number of objects.
>
> Say you have the objects:
> a,b,c,d,e, so in total 5 which gives you 5!/(2!*3!) = 10 possibilities to list them without any doubles:
>
> abc
> abd
> abe
> acd
> ace
> ade
> bcd
> bce
> bde
> cde
>
> I have solved this problem for any number (well up to some computer limit anyway) in three FOR loops but for large numbers this is rather small...
>
> can you think of a better way than using loops to list all these possibilites?
>
> thanks!!
>


Sorry, instead of small it should say slow...stupid autocorrect...
Reply With Quote
  #3 (permalink)  
Old 07-13-2012, 09:28 PM
Paul van Delst
Guest
 
Posts: n/a
Default Re: Fastest way to list combinations

Hello,

On 07/13/12 16:51, antar3s86@gmail.com wrote:
> Hi
>
> I have to solve a problem which includes listing all possible combinations to form a triplet for a given number of objects.
>
> Say you have the objects:
> a,b,c,d,e, so in total 5 which gives you 5!/(2!*3!) = 10 possibilities to list them without any doubles:
>
> abc
> abd
> abe
> acd
> ace
> ade
> bcd
> bce
> bde
> cde
>
> I have solved this problem for any number (well up to some computer limit anyway) in three FOR loops but for large numbers this is rather small...
>
> can you think of a better way than using loops to list all these possibilites?
>
> thanks!!
>


Dunno if it's the fastest and/or best way, but have a look at:
http://ftp.emc.ncep.noaa.gov/jcsda/CRTM/idl/
There should be three files.

If you look at the test_combination.pro you will see how to use it.

For example, getting a list of all the combos of three letters from 26:

IDL> t=systime(1) & Test_Combination, 26, 3 & print, systime(1)-t
....lots and lots of output listing the combinations....
22 23 25
22 24 25
23 24 25
Total combinations: 2600
0.032832861
IDL>

You could use this sort of output to generate index arrays to extract your combination of letters from string arrays.

Anyhoo, hope they're useful.

cheers,

paulv

p.s. There may be a native solution for this as well. I wrote those routines a while back... perhaps even as an
exercise. Can't recall.
Reply With Quote
  #4 (permalink)  
Old 07-15-2012, 03:23 PM
Jeremy Bailin
Guest
 
Posts: n/a
Default Re: Fastest way to list combinations

On 7/13/12 6:21 PM, antar3s86@gmail.com wrote:
> Hi
>
> I have to solve a problem which includes listing all possible combinations to form a triplet for a given number of objects.
>
> Say you have the objects:
> a,b,c,d,e, so in total 5 which gives you 5!/(2!*3!) = 10 possibilities to list them without any doubles:
>
> abc
> abd
> abe
> acd
> ace
> ade
> bcd
> bce
> bde
> cde
>
> I have solved this problem for any number (well up to some computer limit anyway) in three FOR loops but for large numbers this is rather small...
>
> can you think of a better way than using loops to list all these possibilites?
>
> thanks!!
>


You could try COMBIGEN in JBIU.

http://astroconst.org/jbiu/jbiu-doc/math/combigen.html

-Jeremy.
Reply With Quote
  #5 (permalink)  
Old 07-16-2012, 10:12 AM
antar3s86@gmail.com
Guest
 
Posts: n/a
Default Re: Fastest way to list combinations

> You could try COMBIGEN in JBIU.
>
> http://astroconst.org/jbiu/jbiu-doc/math/combigen.html
>
> -Jeremy.


That's the way to go I think!

Thanks
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 04:22 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.