Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2008

Tip: Looking for answers? Try searching our database.

combinations

Thread view: 
Mario - 10 Mar 2008 12:18 GMT
If I have "n" numbers, how to list it in every possible combination. Example
for 3 numbers:
3, 7, 21
1. combination is: 3,7,21
2. combination is:7,3,21
3. combination is: 21,3,7
rossum - 10 Mar 2008 12:56 GMT
>If I have "n" numbers, how to list it in every possible combination. Example
>for 3 numbers:
>3, 7, 21
>1. combination is: 3,7,21
>2. combination is:7,3,21
>3. combination is: 21,3,7

You are asking about "permutations" here, not "combinations".  A
permutation is the same items in a different order, as you have shown.
A combination is a different selection from the group of items.
Combinations would be:

1:  3, 7
2:  3, 21
3:  21
4:  3, 7, 21
etc.

Try googling for "permutation algorithm"

rossum
Markus Tazl - 10 Mar 2008 19:30 GMT
> If I have "n" numbers, how to list it in every possible combination. Example
> for 3 numbers:
> 3, 7, 21
> 1. combination is: 3,7,21
> 2. combination is:7,3,21
> 3. combination is: 21,3,7

As far as i know Robert Sedgewick had an article on permutation on his
website,
maybe searching http://www.cs.princeton.edu/~rs/ might be helpful.

best regards
Markus Tazl
Roedy Green - 11 Mar 2008 02:11 GMT
>If I have "n" numbers, how to list it in every possible combination. Example
>for 3 numbers:
>3, 7, 21
>1. combination is: 3,7,21
>2. combination is:7,3,21
>3. combination is: 21,3,7

You have combinations and permutations confused.

See http://mindprod.com/jgloss/permutation.html
http://mindprod.com/jgloss/combination.html
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Stefan Ram - 11 Mar 2008 03:01 GMT
>If I have "n" numbers, how to list it in every possible combination. Example
>for 3 numbers:
>3, 7, 21
>1. combination is: 3,7,21
>2. combination is:7,3,21
>3. combination is: 21,3,7

 As others already have explained, these are not combinations,
 but permutations.

 Permutations are a part of the library »ram.jar«:

public class Main
{ public static void main( final java.lang.String[] args )  
 { java.lang.Object[] hand = new java.lang.Object[]{ "T", "H", "E"  };
   for
   ( final java.lang.Object[] p :
     new de.dclj.ram.system.iteration.Permutations( hand ))
   java.lang.System.out.print( java.util.Arrays.toString( p )); }}

[T, H, E][T, E, H][H, T, E][H, E, T][E, T, H][E, H, T]

http://www.purl.org/stefan_ram/pub/ram-jar


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.