File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ Programs in this folder can be run from the command line like so:
1010perl triple.pl
1111```
1212
13+ ```
14+ perl permutations.pl I like carrots
15+ ```
16+
1317```
1418perl top_ten_scorers.pl < ../test/wnba_input
1519```
@@ -18,6 +22,7 @@ To run the tests on a Unix-like shell:
1822
1923```
2024./test.sh
25+
2126```
2227
2328## About Perl
Original file line number Diff line number Diff line change 1+ use strict;
2+ use warnings;
3+
4+ sub print_permutations {
5+ my ($a , $n ) = @_ ;
6+ if ($n <= 0) {
7+ print join (" \t " , @$a ), " \n " ;
8+ } else {
9+ for my $i (0 .. $n - 1) {
10+ print_permutations($a , $n - 1);
11+ my $j = $n % 2 == 0 ? 0 : $i ;
12+ @$a [$j , $n ] = @$a [$n , $j ];
13+ }
14+ print_permutations($a , $n - 1);
15+ }
16+ }
17+
18+ print_permutations(\@ARGV , scalar (@ARGV ) - 1);
You can’t perform that action at this time.
0 commit comments