diff options
| author | E. Choroba <choroba@matfyz.cz> | 2023-01-24 23:15:27 +0100 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2023-01-24 23:15:27 +0100 |
| commit | b9cdaf3ff2710711b1ea05d46f7b9a485bfa2173 (patch) | |
| tree | af2770191e2ffcf2bce0fc3f7e148cf7b96f4ee6 | |
| parent | 27b88f614b9bb53872ef0da19a56087505836db0 (diff) | |
| download | perlweeklychallenge-club-b9cdaf3ff2710711b1ea05d46f7b9a485bfa2173.tar.gz perlweeklychallenge-club-b9cdaf3ff2710711b1ea05d46f7b9a485bfa2173.tar.bz2 perlweeklychallenge-club-b9cdaf3ff2710711b1ea05d46f7b9a485bfa2173.zip | |
Add solutions to 201: Missing Numbers & Penny Piles by E. Choroba
| -rwxr-xr-x | challenge-201/e-choroba/perl/ch-1.pl | 22 | ||||
| -rwxr-xr-x | challenge-201/e-choroba/perl/ch-2.pl | 10 |
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-201/e-choroba/perl/ch-1.pl b/challenge-201/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..8e548b4bc0 --- /dev/null +++ b/challenge-201/e-choroba/perl/ch-1.pl @@ -0,0 +1,22 @@ +#! /usr/bin/perl +use warnings; +use strict; +use experimental 'signatures'; + +sub missing_numbers($arr) { + my %missing; + @missing{0 .. @$arr} = (); + delete @missing{@$arr}; + return [keys %missing] +} + +use Test2::V0; +plan 2 + 2; + +is missing_numbers([0, 1, 3]), [2], 'Example 1'; +is missing_numbers([0, 1]), [2], 'Example 2'; + +is missing_numbers([]), [0], 'Empty input'; +is missing_numbers([10, 11, 12]), + bag { item $_ for 0 .. 3 }, + 'Missing more than one'; diff --git a/challenge-201/e-choroba/perl/ch-2.pl b/challenge-201/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..8066dd234d --- /dev/null +++ b/challenge-201/e-choroba/perl/ch-2.pl @@ -0,0 +1,10 @@ +#! /usr/bin/perl +use warnings; +use strict; + +use Importer ntheory => + partitions => { -as => 'penny_piles' }; + +use Test::More tests => 2; +is penny_piles(5), 7, 'Example 1'; +is penny_piles(49), 173525, 'Larger'; |
