diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-10-17 11:49:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-17 11:49:17 +0100 |
| commit | 2566c9de6a515e0bebc5ef4b3e61066d77a5010d (patch) | |
| tree | 184e8f2a57f7e8a9aa6cdcf1cf304b5e7dde8996 | |
| parent | c5ed2c98762a4b56a628419317c14dfd8e276b74 (diff) | |
| parent | 7c3d260d9752167d755d9ca924974b69b1d44246 (diff) | |
| download | perlweeklychallenge-club-2566c9de6a515e0bebc5ef4b3e61066d77a5010d.tar.gz perlweeklychallenge-club-2566c9de6a515e0bebc5ef4b3e61066d77a5010d.tar.bz2 perlweeklychallenge-club-2566c9de6a515e0bebc5ef4b3e61066d77a5010d.zip | |
Merge pull request #5037 from LubosKolouch/master
Challenge 134 Task1 LK
| -rw-r--r-- | challenge-134/lubos-kolouch/perl/ch-1.pl | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-134/lubos-kolouch/perl/ch-1.pl b/challenge-134/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..8395b3e464 --- /dev/null +++ b/challenge-134/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,34 @@ +use strict; +use warnings; +use Algorithm::Combinatorics qw/permutations/; + +sub get_10_pandigital { + + my @list = ( 2 .. 9 ); + unshift @list, 0; + unshift @list, 1; + + my $counter = 1; + my $iter = permutations( \@list ); + + my @result; + + while ( my $p = $iter->next ) { + push @result, join "", @$p; + $counter++; + last if $counter == 11; + } + + return \@result; +} + +use Test::More; + +is_deeply( + get_10_pandigital(), + [ + 1023456789, 1023456798, 1023456879, 1023456897, 1023456978, 1023456987, + 1023457689, 1023457698, 1023457869, 1023457896 + ] +); +done_testing; |
