aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwanderdoc <wanderdoc@users.noreply.github.com>2025-06-29 17:14:22 +0200
committerGitHub <noreply@github.com>2025-06-29 17:14:22 +0200
commit73f1070944ee9169cd9b56a85dcfeba6d9aa1ebf (patch)
tree7b0a96f8732526457dee04db38c40d6812a99076
parent3495f39a1245ae75e4aa8c3862186211a5b33a5b (diff)
downloadperlweeklychallenge-club-73f1070944ee9169cd9b56a85dcfeba6d9aa1ebf.tar.gz
perlweeklychallenge-club-73f1070944ee9169cd9b56a85dcfeba6d9aa1ebf.tar.bz2
perlweeklychallenge-club-73f1070944ee9169cd9b56a85dcfeba6d9aa1ebf.zip
Create ch-1.pl
-rw-r--r--challenge-327/wanderdoc/perl/ch-1.pl53
1 files changed, 53 insertions, 0 deletions
diff --git a/challenge-327/wanderdoc/perl/ch-1.pl b/challenge-327/wanderdoc/perl/ch-1.pl
new file mode 100644
index 0000000000..0455e0a902
--- /dev/null
+++ b/challenge-327/wanderdoc/perl/ch-1.pl
@@ -0,0 +1,53 @@
+#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given an array of n integers.
+Write a script to find all the missing integers in the range 1..n in the given array.
+
+Example 1
+
+Input: @ints = (1, 2, 1, 3, 2, 5)
+Output: (4, 6)
+
+The given array has 6 elements.
+So we are looking for integers in the range 1..6 in the given array.
+The missing integers: (4, 6)
+
+
+Example 2
+
+Input: @ints = (1, 1, 1)
+Output: (2, 3)
+
+
+Example 3
+
+Input: @ints = (2, 2, 1)
+Output: (3)
+
+
+Example 4
+
+Input: @ints = (2, 1)
+Output: ()
+=cut
+
+
+
+
+
+use Test2::V0 -no_srand => 1;
+is( [missing_integers(1, 2, 1, 3, 2, 5)], [4, 6], 'Example 1');
+is( [missing_integers(1, 1, 1)], [2, 3], 'Example 2');
+is( [missing_integers(2, 2, 1)], [3], 'Example 3');
+is( [missing_integers(2, 1)], [], 'Example 1');
+done_testing();
+
+sub missing_integers
+{
+ my @arr = @_;
+ my %lookup = map {$_ => undef} @arr;
+ return grep { not exists $lookup{$_} } 1 .. @arr;
+}