From b9cdaf3ff2710711b1ea05d46f7b9a485bfa2173 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Tue, 24 Jan 2023 23:15:27 +0100 Subject: Add solutions to 201: Missing Numbers & Penny Piles by E. Choroba --- challenge-201/e-choroba/perl/ch-1.pl | 22 ++++++++++++++++++++++ challenge-201/e-choroba/perl/ch-2.pl | 10 ++++++++++ 2 files changed, 32 insertions(+) create mode 100755 challenge-201/e-choroba/perl/ch-1.pl create mode 100755 challenge-201/e-choroba/perl/ch-2.pl 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'; -- cgit