in reply to Please help me understand this permutation sub?
#!/usr/bin/perl use strict; use warnings; sub permutation { my ($perm, $depth, @set) = @_; print "\t" x $depth, "@set\n"; print "$perm\n" unless @set; permutation($perm . $set[$_], $depth + 1, @set[ 0 .. $_ - 1], @set[ $_ + 1 .. $#set] ) for 0 .. $#set; } my @input = (qw/a b c d/); permutation("", 1, @input);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Please help me understand this permutation sub?
by mdunnbass (Monk) on Dec 09, 2020 at 13:55 UTC | |
by LanX (Saint) on Dec 09, 2020 at 14:10 UTC |