A solution using glob to generate the 4-digit numbers, split, sort and join to get only ascending values then grep and a regex to sift out repeating digits. A hash is populated so that any duplicate values go into the same key/value pair and are therefore masked. Finally print the sorted values.
johngg@abouriou ~/perl/Monks $ perl -Mstrict -Mwarnings -E ' my $digs = q{0,1,2,3,4,5,6,7,8,9}; my $globStr = qq|{$digs}| x 4; my %combs = map { $_ => 1 } grep { ! m{(.).*\1} } map { join q{}, sort split m{} } glob $globStr; say for sort keys %combs;' | wc -l 210
I hope this is of interest.
Update: Can be shortened by acting directly on an anonymous hash but there's a warning unless you silence it (which, sadly, makes it not so short again).
johngg@abouriou ~/perl/Monks $ perl -Mstrict -Mwarnings -E ' my $digs = q{0,1,2,3,4,5,6,7,8,9}; my $globStr = qq|{$digs}| x 4; say for do { no warnings qw{ experimental::autoderef }; sort keys { map { $_ => 1 } grep { ! m{(.).*\1} } map { join q{}, sort split m{} } glob $globStr }; };' | wc -l 210
Cheers,
JohnGG
In reply to Re: list of four digit lock combinations without repeated digits
by johngg
in thread list of four digit lock combinations without repeated digits
by Lotus1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |