Printing all permutations

Hi,
My sister is a CS student, and she currently learns recursion. She's got an exercise is to write a program that gets an array of integers and recursively prints all of its permutations (all elements in all possible orders).
For example, if the input array is {1, 2}, the program should print this:
1 2
2 1
The code was not too difficult to write, and it works now. The exercise has a second requirement, though, that the output of our program should be identical to the output of the school solution. That is, it's not enough that we print all permutations, we must do it the same order as they do.
And that's where we're kind of stuck, because the order of the output in the school solution is not the same as ours, and we're unsure how to modify our code reproduce their output.
For example, for input array {1, 2, 3}, our code would print
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
whereas the school solution would print
1 2 3
1 3 2
2 1 3
2 3 1
3 2 1 //last 2 lines come in reverse order
3 1 2
More (off site) examples
{1, 2, 3, 4}: http://rafb.net/p/I2DMPZ57.nln.html
{1, 2, 3, 4, 5}: http://rafb.net/p/EkQoJ668.nln.html
{1, 2, 3, 4, 5, 6}: http://rafb.net/p/RVBtVf67.nln.html
If somebody can identify a pattern in the school solution, please give us a hint as to how we should match it with our code.
The relevant part of our code is here: http://rafb.net/p/4oEsMB53.nln.html
Thanks

thanks for your input.
its always good to have something to kick start you into thinking again :). rather than starting blankly and tugging your hair.
anyway .. unfortunately none of the workarounds seemed to work out. they did seem to be describing a slightly different problem though - one where the text appears but the window does not scroll .. i don't get any text at all until the end (and then it does scroll).
i tried it out with a standard TextArea and got the scrolling, the problem is it is much slower than when i run it at the command prompt, and it slows down further. is this anything to do with its running lower on memory (as cmd prompt discards most of the data as it generates more), so do i need to fix that first to cure this, or is it a problem with the TextArea. and will it be a problem with any component i choose to print out on? i guess if it is ill just have to scrap that idea.
thanks again
btw - u are right, it shouldve been long - i'd corrected it since i posted the code .. sorry

Similar Messages

  • Enumerate all Permutations of integers 1 to n

    hi all,
    I have to code a program that can take an input, let's say n, and then output all permutations of from 1 to n. So if n were 3 my program should output:
    123
    132
    213
    231
    321
    312
    Any suggestions? I know there is a function provided in the standard C library called nextpermutations() that does something like this. Is there any such thing in JAVA, and if so how do I use it?

    The following is for 6P3.
    final public class Permutation6{
       static int N = 6,p=3;
    public static void main(String[] args){
       MyList L0 =new MyList(0,null);    
       MyList list=null;
       for(int i=0;i<N;i++){
          for(int k=0;k<N;k++){
              if(k!=i){
                 for(int q=0;q<N;q++){
                        if(q!=i&&q!=k){
                            L0=new MyList(i,new MyList(k,new MyList(q,null)));
                            list= L0;
                            while(list!=null){
                                    System.out.print(String.valueOf(list.getValue()));
                                    list=list.getNext();
                            }//end of while
                            System.out.println();
                      }//end of inner if
                }//end of inner for
             }//end of outer if
           }//end of med for
        }//end of outer for
    } //end of main
    } //end of class Permutation3From5
    class MyList{
      int n;
    MyList next;
    MyList(int n, MyList list){
    this.n=n;
    this.next=list;
    MyList getNext(){
        return this.next;
    public int getValue(){
        return this.n;
    }                 

  • Is there a way in Pages to show and print all the added "comments?" (those you add by highlighting text)  I'd like students to be able to view my comments on printed version of their papers.

    Is there a way in Pages to show and print all the added "comments?" (those you add by highlighting text)  I am a teacher, and I would  like students to be able to view my comments on printed versions of their papers. I know word displays the comments off to the side of the document, and those comments can be viewed all at once and printed alongside the document.

    There doesn't appear to be a way to print conmments in either Pages or Numbers in the Mavericks versions.
    Jerry

  • How can I print all the open tabs from the Reader?

    One of my users subscirbes WSJ Online and uses the Reader to read articles. The user would like to know if he can print all the open tabs in Reader at once instead of one tab or article at a time.
    OS X10.8.2

    Hi,
    Do you mean that you want to print the ABAP code to SAPscrip form ?
    Svetlin

  • How can i print all the contect of the code in sapscript window ? ?

    how can i print all the contect of the code in sapscript window ? ?

    Hi,
    Do you mean that you want to print the ABAP code to SAPscrip form ?
    Svetlin

  • How can i print all the tab pages not just the first page (tab)

    how can i print all the tab pages not just the first page (tab)

    You would need to do this programmatically. Here's one way:
    Attachments:
    Example_VI_BD6.png ‏3 KB

  • How do I print just 1 web page in FF 29 ? With 29 you can only change the first field ( 1 of 5, 2 of 5, 3 of 5, etc. ) That means I can only print all 5 pages,

    So I cant seem to print just the 1st of 5 pages. The default setting , 1 of 5, will print all 5 pages. The 2nd field can not be altered, as it could in previous FF versions, to 1 of 1. Therefore, I can only print all 5 pages, 2 through 5, 3 through 5, etc. WTF - I keep wasting print paper. I got the print edit add-on but that doesn't seem to help. I have been through several FF versions and do not like the format of 29.

    Actually, with the [https://addons.mozilla.org/en-US/firefox/addon/print-edit/ Print Edit addon], if I click the down arrow I get the old print format options and can do it.

  • How to print all columns in one page

    Hi,
    Can anybody explain me how to print all columns in one page.we have around 15 to 20 columns for 4 reports and all these reports are build on one multiprovider.we are using BW 3.5.
    Can anyone explain me  how to print ALL COLUMNS IN ONE PAGE  .currently they are getting all columns in 2 to 3 pages. They are using PORTAL to run the reports here.
    Is it possible to do by customizing Webtemplate or by macros in Workbook.Please help me
    Edited by: kotha123 on Oct 11, 2010 5:58 PM

    Hi,
    Your best bet is to use a workbook template or else Excel to pdf option...Thanks

  • Can VC print all data in a table?

    Hello!
      Can VC print all data in a table?
    Best Reagrds!
    csquare.

    I write it in this post:
    Re: Qusetion about Table View.
    It is possible, that you have to use the paging options.
    Regards,
    Marcel

  • How do I get a text box to expand by user and print all text?

    I am creating a form in Adobe Live Cycle Designer that was converted from a Word file that contains many text boxes.  I would like the text box to expand to accomodate each user's text in edit mode.  When the form is printed - all the entered text should print.  Even though I set the text box to allow multiple lines, all the user sees when they print is a box with just a couple of lines and a red + in the corner indicating that there is more text.  There must be a work around?  I am not very proficient in this software so would love someone to give me the necessary steps.  Thanks.

    It is a dynamic form feature available in Designer. To get more information, ask in the LiveCycle forum.

  • I am trying to print all the PDF pages in a range of 5 pages but can only print one page at a time . . . It will print the current page, but not all or pages 1-5.  Can this be overcome?

    I am trying to print all the PDF pages in a range of 5 pages but can only print one page at a time . . . It will print the current page only, but not all or pages 1-5.  I need to go to the next subsequent page and command to print current page; continuing with this procedure until all pages are printed one at a time. Can this be overcome?

    You can use printPages(1, 5), however I need to know how you print current page.

  • How can i print all pages instead of only the first page using firefox

    How can i set firefox to print off my mac to my lexmark printer all pages i want. It is only printing the first page as of about 4 days ago
    == This happened ==
    Every time Firefox opened
    == about 4 days ago. it works ok on safari!

    Then duplicate that button to pages 3-23.
    To do that effectively go to Form Edit mode, right-click the button and select Duplicate Across Pages.

  • How to print all pages using ALV from CL_SALV_TABLE?

    Dear friends,
    I have a report which displays a dynamic internal table using CL_SALV_TABLE. The display format is normal list.
    And since this dynamic internal table is big, I have divided it into a sub internal table which displays 10 columns in one page at one time. And each page is displayed using a customized button that I set as MyFunction.
    The problem is, when I click List->Print or Ctrl-P, the system will only send to spool the current page even though in the Print dialog box, I choose Print All option.
    Is there a way to rectify this? Thanks.

    Hi,
    Try this..code...the above FM expects purchasing organization..revised code below mentioned..
    please try..
    DATA: kdy_val(8) VALUE '/110'.
      SET PARAMETER ID 'LIF' FIELD 'VENDOR'.   " Pass the vendor
      SET PARAMETER ID 'KDY' FIELD KDY_VAL.
      CALL TRANSACTION 'XK03' AND SKIP FIRST SCREEN.
    Thanks
    Naren

  • Report not printing all the characters -main section width greater than 11"

    Hi,
    I am trying to build/modify a Report (used in Oracle Apps) which will be printed on some perforated paper. The perforated paper is little bit wider (11.25 inches) than the regular A4 size paper.
    The problem is when I print the report in Oracle Apps, the report isn’t printing all the characters at end of the page. I adjusted the page width to 11.25" in the main section's property palette, but the same thing is happening. Another point to mention is, I should use all of paper space.
    I am not sure if it’s a report builder issue or oracle apps issue.
    Any help is appreciated.
    Thanks
    Srikanth

    You must have larger margin. Try to make smaller header and/or footer.

  • How not to print all the pages of a smartform? (for tr F150 - Dunning)

    Hi Forum
    We have the follow situation:
      For DUNNING (transaction F150) the user want stamp 3 diferents SMARTFORM.
       For the first time the transaction is executed is required only a list of documents, for the second time (via sample printout, indiv dunn notice or dunn history)  once the legal data of the customer is updated, the user wants the list of documents, a letter for the lawyers and a letter for the client, in the follows executions  (3 and up) the user can require only the list of documents or all smartforms (list and letters)
      Via customizing we can control the normal dunning and the legal dunnig, but once the client is in legal status the transaction create only the legal smarforms.
    We found  an user exit associated  EXIT_SAPF150D_001. in the F150 transaction, but is not complete, in sense that are failed some parameters .
      Another option is create an unique smartform with 3 pages where we can control the case for the print, but here is where we ask: How we can do to print a specific page of the smartform without print all of them (how can we print the 2nd and 3rd page without print the firs one) ??
    To control the 3rd execution, we can create a dictionary table with a flag .
    Thank you for your help

    You could create a report containing all the single reports in one using UNION. This report could be placed on a "hidden" page. The link for downloading that report you can place on your page. That should work.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    https://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494

Maybe you are looking for