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

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")

Replies are listed 'Best First'.
RE: (tye)Re2: permute n elements2
by Anonymous Monk on Oct 28, 2000 at 23:22 UTC
    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")