Show all the possible combinations of n elements in an array???

If I have an array of n elements, how to show all the possible combinations of n elements.
What is the java library for doing the combinations??
For example,
public class CombinationTest
{     public static void main(String[] args)     
     {     ArrayList letters = new ArrayList();
          leters.add("s1");
          leters.add("s2");
          leters.add("s3");
Find all the combinations of 3 elements: C(3,2). Here's the result:
1) s1, s2
2) s1, s3
3) s2, s3
}

There isn't a built-in API method for this. Still, combinations are pretty easy. Pseudocode (borrowing notation from ML and GJ, and assuming immutable sets): Set<Set<Object>> getCombinations(int itemsInCombo, Set<Object> itemsToCombine)
    // Handle base case and exceptional cases
    if (itemsInCombo = 0) return Set.emptySet();
    if (itemsInCombo < 0) throw new Exception("?!");
    // Recursive case
    Object o = itemsToCombine.first(); // use iterator - may throw exception
    // Get combos with first element
    Set<Set<Object>> rv = map (x => x.add(o)) getCombinations(itemsInCombo - 1, itemsToCombine.remove(o));
    // Add combos without first element
    rv.add(getCombinations(itemsInCombo, itemsToCombine.remove(o)));
    return rv;
}

Similar Messages

  • Sql Query : Sum , all the possible combination of rows in a table

    SQL Server 2008 R2
    Sample Table structure
    create table TempTable
    ID int identity,
    value int
    insert into TempTable values(6)
    insert into TempTable values(7)
    insert into TempTable values(8)
    insert into TempTable values(9)
    insert into TempTable values(10)
    I actually want something like below,
    that It returns rows such that, it has the sum of all the remaining rows , as shown below.
    I will ignore the repeated rows.
    6+7
    6+8
    6+9
    6+10
    6+7+8
    6+7+9
    6+7+10
    6+8+9
    6+8+10
    6+9+10 
    6+7+8+9
    6+7+8+9+10

    This makes no sense. What about NULLs? What about duplicate values? You have rows, so you have many combinations. We know that this set totals to 39, so there is no subset totals to half of any odd number.  19.5
    in this case. 
    None of your examples are
    even close! 
     6+7 = 13
    the remaining rows 8+9+10 = 27, so you failed! 
    Want to try again?
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • I have Adobe Photoshop Elements 10 plus I create PDF files for work some are scan pdf docs. When I install Photoshop Elements 10 it DOES convert all the PDF files to Photoshop Elements-10 Docs. it even changes and shows the PSE-10 Icon. So I am alway inst

    I have Adobe Photoshop Elements 10 plus I create PDF files for work some are scan pdf docs. When I install Photoshop Elements 10 it DOES convert all the PDF files to Photoshop Elements-10 Docs. it even changes and shows the PSE-10 Icon. So I am alway installing PSE-10 or uninstalling it. If I send the  PDF file that has been automatically converted to a PSE-10 the person I send the file to can not open it because they do not have PSE-10. What can I do to stop PSE-10 from converting my PDF files? Don't tell me to upgrade PSE-10 I tried their on-line program and  it is too advance for a hobby photographer like myself and their Help Desk is impossible to reach.

    Hi,
    Can you please share the logs?
    You can use the Adobe  Log Collector tool (Log Collector Tool) and share the corresponding zip file @ [email protected]
    Thanks,
    Shikha

  • A report that shows all the elements with their setting

    Hi
    Is there a way to write a report in discoverer which will show all the elements set up in Oracle with there settings e.g. are they taxable or niable etc.
    Alternatively is there a standard report in HRMS which would give the same results.
    Thanks in advance

    Not really as such. Taxable and Niable elements feed to the appropriate taxable or niable balances therefore, you will need to run a report against what elements are fed into these balances. I doubt that there will be anything as standard in teh pre shipped EUL's that will enable you to do this, however, for simple one of why don't you just call up teh balances in teh application and see what elemenst feed into them.
    Cheers
    Scott

  • How can I show all the results returned by a sql query?

    Hi guys,
    I need your help.
    Let's say I have one table: TableA. Fields of TableA are aleg, anon, apes. The following sentence can return, in general, several rows: select anon from TableA where aleg = somevalue. I'd like to show the result of column anon but no luck. If I try to show the results in a TextArea and the origin is an sql query only shows the first row value. I tried Show as: show as text (based in PLSQL) and coding an anonymous plsql block as
    DECLARE
    v_anon TableA.anon%TYPE;
    CURSOR v_cur IS
         select anon from TableA where aleg = somevalue;
    BEGIN
    OPEN v_cur;
    LOOP
    FETCH v_cur INTO v_anon;
    EXIT WHEN v_cur%NOTFOUND;
    :FIELD_IN_FORM := v_anon;
    END LOOP;
    CLOSE v_cur;
    END;
    but in this case it's not shown any result.
    So the first question is what kind of field should I use to show the result. And the second one is what can I do to being able to show all the results returned by the query (provided that is more than one single row).
    regards

    Hi Denes,
    Just starting with apex. I think I know how to show the results in a report region. I've simplified the posted question.
    A more detailed question would be: Suppose you have a region where you have put several text areas to accommodate the result of a multi-column query (lets say for TableA) that only returns one row, each column value returned put in a different text area. Also you want to show the values of other fields in TableB that depends on some value just retrieved from TableA and that you want all values retrieved (from TableA and the linked TableB) to be show in the same region. Is that possible? If yes, how?
    Thank you in advance

  • Exporting PDF document to Excel.  When I export a PDF document to Excel containing lists of  people the Excel page shows all the names on  one line several inches deep instead of on separate lines which makes editing impossible.  What am I doing wrong?

    Exporting PDF document to Excel.  When I export a PDF document to Excel containing lists of  people the Excel page shows all the names on  one line several inches deep instead of on separate lines which makes editing impossible.  What am I doing wrong?

    Murray is right. Padding (and margins) is added to the width. However, when using percentages, you should never use figures that add up to exactly 100%.
    Browsers need to convert the percentages to pixels. Because pixels must be whole numbers, some percentages are rounded up, which results in the final element dropping down below its neighbours. With percentages, it's much safer to use values that add up to 98% (99% often works, but 98% is safer).

  • Parse XML: how to get all the sub nodes of an element

    Hello, I am using org.w3c.dom to parse an XML file. I want to get all the information under an elements, including all the sub nodes and sub sub nodes, maybe output as a String or String[ ]. How should I do it with org.w3c.dom?
    e.g. I want to get all the text within<datafile></datafile>:
    <datafile>
    blablabla
    <id> bla <description>bla</description></id>
    </datafile>
    I write:
    Node element = InterfaceDOM.getElementsByTagName("datafile");
    how can I return all the sub content within this element?
    Thanks a lot!

    http://www.developerfusion.co.uk/show/2064/

  • How to show all the user entry variables in a workbook.

    Hi,
    My user need to see in the workbook all variables he had entered in the variable entry popup at the openning of the workbook.
    I know how to show all the variables, included the hardcoded variable in the query (with a text element, select the checkbox "Display All Statics Filters"), but I need only the user entry variables.
    There is a way to print only these variables?
    Thank you

    Thanks, but the problem is that this workbook is my Global default workbook used for all the queries. So I only want the user entry variables visible automaticly.
    There is a way to do that ?
    For information, i'm using Netweaver 7.
    Thank you

  • Show all the structure in the Query

    Hi people,
    I would like to know if there is some way to show all the structure I created by hierarchy to my query, enven if some nodes there isn´t any data.
    I have configurated to show only the lines there is amount. It means it won´t show the lines that have zeros.
    But the structure (all of the nodes) I would like to show, include that one there aren´t any datas.
    Thanks in advance,
    Rosana.

    Jaya,
    You are 10. It worked!.
    I only will leave opened this request yet because I would like a new suggestion.
    For exemple, I have the hierarchy but on the side "colum"  I already have a structure where is restricted by data because it is a report  "Year to Date".
    On this case, is it possible to do something to show all the structure of the hierarchy?
    Ps.: If it is necessary close this request and open a new one, you can tell me ok?
    Thanks a lot,
    Rosana.

  • Vertical scrollbar not showing all the records when I scroll down.

    Vertical scrollbar not showing all the records when I scroll down.
    Using Oracle forms 10g , operating system windows
    I have two fields with number of items dispayed = 15.
    I have a vertical scroll bar with them. There are 34 records in the table but the scrollbar only shows 15 records.
    Here are the properties for block / scrollbar.
    WORK_CATEGORY
    - Subclass Information                           
    - Comments                                       
    * Navigation Style                                Same Record
    - Previous Navigation Data Block                 
    - Next Navigation Data Block                     
    - Current Record Visual Attribute Group          
    - Query Array Size                                0
    - Number of Records Buffered                      0
    * Number of Records Displayed                     60
    * Query All Records                               No
    - Record Orientation                              Vertical
    * Single Record                                   No
    - Database Data Block                             Yes
    - Enforce Primary Key                             No
    - Query Allowed                                   Yes
    - Query Data Source Type                          Table
    * Query Data Source Name                          WORK_CATEGORY
    * Query Data Source Columns                      
    * Column Name                                   JOB_TYPE
    * Column Type                                   VARCHAR2
    - Column Type Name                             
    - Parent Column                                
    * Length                                        30
    * Precision                                     0
    * Scale                                         0
    * Mandatory                                     Yes
    * Column Name                                   WORK_CATEGORY
    * Column Type                                   VARCHAR2
    - Column Type Name                             
    - Parent Column                                
    * Length                                        30
    * Precision                                     0
    * Scale                                         0
    * Mandatory                                     Yes
    - Query Data Source Arguments                    
    - Alias                                          
    - Include REF Item                                No
    * WHERE Clause                                   
    * ORDER BY Clause                                 job_type
    - Optimizer Hint                                 
    - Insert Allowed                                  Yes
    - Update Allowed                                  Yes
    - Locking Mode                                    Automatic
    - Delete Allowed                                  Yes
    - Key Mode                                        Automatic
    - Update Changed Columns Only                     No
    - Enforce Column Security                         No
    - Maximum Query Time                              0
    * Maximum Records Fetched                         0
    - DML Data Target Type                            Table
    - DML Data Target Name                           
    - Insert Procedure Name                          
    - Insert Procedure Result Set Columns            
    - Insert Procedure Arguments                     
    - Update Procedure Name                          
    - Update Procedure Result Set Columns            
    - Update Procedure Arguments                     
       Don't know where am I going wrong. I'll really appreciate if you can help me in this.
    Thanks.
    Edited by: 831050 on Sep 14, 2011 8:05 AM

    One of the items is a list item.. here are it's properties:
    * Name                                          JOB_TYPE
    * Item Type                                     List Item
    - Subclass Information                         
    - Comments                                     
    - Help Book Topic                              
    - Enabled                                       Yes
    * Elements in List                             
    * Label                                      
    * List Item Value                             LIST20
    * List Style                                    Combo Box
    - Mapping of Other Values                      
    - Implementation Class                         
    - Case Restriction                              Mixed
    - Popup Menu                                   
    - Keyboard Navigable                            Yes
    - Mouse Navigate                                Yes
    - Previous Navigation Item                     
    - Next Navigation Item                         
    - Data Type                                     Char
    - Data Length Semantics                         Null
    - Maximum Length                                30
    - Initial Value                                
    * Required                                      Yes
    * Copy Value from Item                         
    - Synchronize with Item                        
    - Calculation Mode                              None
    - Formula                                      
    - Summary Function                              None
    - Summarized Block                             
    - Summarized Item                              
    - Current Record Visual Attribute Group        
    - Distance Between Records                      0
    * Number of Items Displayed                     15
    - Database Item                                 Yes
    * Column Name                                   JOB_TYPE
    - Primary Key                                   No
    - Query Only                                    No
    - Query Allowed                                 Yes
    - Insert Allowed                                Yes
    - Update Allowed                                Yes
    - Update Only if NULL                           No
    - Visible                                       Yes
    * Canvas                                        CANVAS2
    - Tab Page                                     
    * X Position                                    47
    * Y Position                                    137
    * Width                                         187
    * Height                                        18
    - Visual Attribute Group                        DEFAULT
    - Prompt Visual Attribute Group                 DEFAULT
    - Foreground Color                             
    * Background Color                              white
    - Fill Pattern                                 
    - Font                                         
    * Font Name                                     Tahoma
    * Font Size                                     10
    * Font Weight                                   Demilight
    * Font Style                                    Plain
    * Font Spacing                                  Normal
    * Prompt                                        Job Type
    - Prompt Display Style                          First Record
    * Prompt Justification                          Start
    * Prompt Attachment Edge                        Top
    - Prompt Alignment                              Start
    * Prompt Attachment Offset                      10
    * Prompt Alignment Offset                       0
    - Prompt Reading Order                          Default
    - Prompt Foreground Color                      
    - Prompt Font                                  
    * Prompt Font Name                              Tahoma
    * Prompt Font Size                              10
    * Prompt Font Weight                            Bold
    * Prompt Font Style                             Plain
    * Prompt Font Spacing                           Normal
    - Hint                                         
    - Display Hint Automatically                    No
    - Tooltip                                      
    - Tooltip Visual Attribute Group               
    - Direction                                     Default
    - Initial Keyboard State                        Default
    - Keyboard State                                Any
        

  • Findling all the xpaths matching a particular element

    Hi,
    I have to build java code using any built-in api (if any) to fetch all the possible XPATHs that match a value provided as input.
    Inputs would be pattern for search and XML from which the xpaths to be built.
    pattern could be an element name,attribute value ,anything in xml etc
    Can you please share any sample code that would do this .
    Thanks in advance
    sam

    Hi,
    I'd probably do it with SAX or XSLT, depending on how the results are processed later.
    Here are some examples close to your requirement :
    http://stackoverflow.com/questions/4746299/generate-get-xpath-from-xml-node-java

  • Is there a way to print something showing all the purchases that have been made and what the total cost is?

    Is there a way to print something showing all the purchases that have been made and what the total cost is?

    While it is not possible to directly print your iTunes account purchase history within the iTunes Store, you can take a screnshot of your purchase history on your computer, and then print that screenshot.
    The following article explains how to review your purchase history:
    http://support.apple.com/kb/HT2727
    This articles explains how to take a screenshot on Mac OS X:
    http://docs.info.apple.com/article.html?path=Mac/10.7/en/mh26782.html
    and this does on windows:
    http://windows.microsoft.com/en-CA/windows-xp/help/setup/take-a-screen-shot

  • I was found I pad Air is not that user friendly than I pad 4 even I pad 2, as I was a TaoBao fans and every time when I get in their link, I pad Air cannot show all the pictures on the screen and very slow. It make me very disappointed about this issue.

    I was found I pad Air is not that user friendly than I pad 4 even I pad 2, as I was a TaoBao (www.taobao.com) fans and every time when I get in their link, I pad Air cannot show all the pictures on the screen and very slow. It make me very disappointed about this.  Could you please help to improve this. Thank you vey much!

    iPad running slow? How to speed up a slow iPad
    http://appletoolbox.com/2012/07/ipad-running-slow-how-to-speed-up-a-slow-ipad/
    If You Think iOS 7 Feels Slow Here’s How to Speed It Up
    http://osxdaily.com/2013/09/23/ios-7-slow-speed-it-up/
    You may have many apps open which can possibly cause the slowdown and possibly the loss of wifi. In iOS 4-6 double tap your Home button & at the bottom of the screen you will see the icons of all open apps. Close those you are not using by pressing on an icon until all icons wiggle - then tap the minus sign. For iOS 7 users, there’s an easy way to see which apps are open in order to close them. By double-tapping the home button on your iPhone or iPad, the new multitasking feature in iOS 7 shows full page previews of all your open apps. Simply scroll horizontally to see all your apps, and close the apps with a simple flick towards the top of the screen.
     Cheers, Tom

  • Configuring instanceconfig file to show all the links except return.

    Hi All,
    I have used the following java script to remove all the links in the drill down report. But now we have requirement to show all the links except return link.
    <style>
    .ResultLinksCell
    display: none;
    </style>
    I have come across the link where srini has suggested to configure instanceconfig.xml file with addition of following elements. I was trying to understand how this prevents only hide the return link. I have tried it in instanceconfig.xml but without any success. Any suggestions for this scenario
    {code} Disable or Hide return link - Business Intelligence Suite Enterprise Edition{code}
    <ServerInstance> <Analysis> <InteractionProperties> <InteractionPropertyAddRemoveValues>false</InteractionPropertyAddRemoveValues> <InteractionPropertyCalcItemOperations>false</InteractionPropertyCalcItemOperations> <InteractionPropertyDrill>false</InteractionPropertyDrill> <InteractionPropertyGroupOperations>false</InteractionPropertyGroupOperations> <InteractionPropertyInclExclColumns>false</InteractionPropertyInclExclColumns> <InteractionPropertyMoveColumns>false</InteractionPropertyMoveColumns> <InteractionPropertyRunningSum>false</InteractionPropertyRunningSum> <InteractionPropertyShowHideSubTotal>false</InteractionPropertyShowHideSubTotal> <InteractionPropertySortColumns>false</InteractionPropertySortColumns> </InteractionProperties> </Analysis> </ServerInstance>
    Thanks,
    Sushil

    Thanks for your reply. <div align=center>Return</div>--> creates link in the main report, but does not remove only Return link but all the links. I have updated the https://forums.oracle.com/thread/2557621 , sorry I completely forgot about this.
    Sushil

  • How to show all the rows of a report in one page

    My report has 30 rows, by default it just show 15 rows. I want to show all the rows just in one page, without cliking link or arrow to see the left.
    In the Layout and Pagination:
    Report Template: template: 15. Standard Report (PPR)
    Pagination Scheme: Row Ranges X to Y (no pagination)
    Display Position: Bottom - Right
    Number of Rows: 1000
    Number of Rows (item) 1000
    Maximum Row Count: 1000
    How to fix it?
    Thanks.
    Jen

    Ok, I think I got it. I needed to blank out Number of Rows(item), Maximum row count and only populate Number of Rows. I was sure I did that before and it didnt work.
    Do you think that the Sessions in Apex can cause unexpected results? I have found that when I make changes I have to log all the way out of Apex, close my browser and reopen everything to ensure that my change took. Does anyone else have this issue? I can move this into a different thread if need be.
    Thx!

Maybe you are looking for

  • Help ME..cc itunes store payment problem

    Help me... i want to buy platinum on my game " celtic heroes ",but i can't. but yesterday i can buy that. It says that I must contact itunes support for complete this transaction. But I can buy app keynote from appstore. How can I solve this? Thanx f

  • How to run the cocoa app directly after completion of downloading ?

    Hi , How to run the cocoa app directly on mac after completion of downloading ? I have a .app at server , I want to run the .app automatically after download and the .app should not save at download directories . Thanks

  • Analysis authorisation settings

    Hi All When using the standard business content characteristics , 0TCAACTVT,0TCAIPROV,and 0TCAVALID, within analysis authorisations. Do these characteristics need flagging as authorisation relevant in all clients, Dev Uat and Prodn, as at present the

  • Text Maintenance behind IT0002 and IT0009

    Hello, We got a requirement to enable the Text Maintenance for IT0002 and IT0009. When going to SPRO -> Personnel Management ->Personnel Administration -> Customizing Procedures -> Infotypes -> Infotypes -> IT02  the Copy Infotype box is checked. Whe

  • Is it possible Messages Settings break Profile Manager?

    I've recently been playing about with the Messages app in ML and ML server. I've got everything working manually, as in going to each machine, logging in as the user and adding their credentials to the Messages app. I'm trying to automate this using