in reply to (tye)Re: permute n elements2
in thread permute n elements2

I ran your program as printed. the following : a a b b b c d should have yielded 420 permutations. i get 4976 the same number as how...permut n..". The text you wrote says "To use it, first sort.... I'm a perl newbie,please give me layman details to make this program work w/o duplicate permutations and I will be eternally grateful to you!!!! email address swanhits@hotmail.com should you choose to be more direct. thanks waiting on your reply!!!

Replies are listed 'Best First'.
(tye)Re2: permute n elements2
by tye (Sage) on Oct 28, 2000 at 05:34 UTC

    I get 420. It appears you ran the wrong program. You use the program just like you showed (the sorting is included in the "Sample use" part of the code).

            - tye (but my friends call me "Tye")
      you were right. however, I copied the text from permuting w/dup...and saved it with , .pl when i ran it from the command prompt it just gave me another command prompt. I had no chance to input any data. oh yeah, can it permute numbers too? my command prompt looks like as follows: perl permnodup.pl then i hit enter. Even if i doubleclick on the icon permnodup.pl the perl msdos window comes on and goes off, instead of waiting for my permutation. What am i doing wrong? I await your enlightenment!!!!!!

        You should enter the words (or letters or numbers) on the command line like "perl permnodup.pl a a a b b c". Feel free to change this part of the code:

        #Sample use: @ARGV= sort @ARGV; do { print "@ARGV\n"; } while( nextpermute(@ARGV) );
        to do something else. Here is a more versatile version:
        #Sample use: my @elts= @ARGV; my $sep= " "; do { if( ! @ARGV ) { print "What to permute? "; my $line= <STDIN>; chomp( $line ); exit 0 if "" eq $line; if( $line =~ / / ) { $sep= " "; @elts= split " ", $line; } else { $sep= ""; @elts= split //, $line; } } @elts= sort @elts; my $cnt= 0; do { print ++$cnt, ": ", join( $sep, @elts ), "\n"; } while( nextpermute(@elts) ); } while( ! @ARGV ); exit 0;

                - tye (but my friends call me "Tye")