From 391da064891c3a64b1cf8d2c9a4ebb8aeb39efbe Mon Sep 17 00:00:00 2001 From: aut0exec <32361472+aut0exec@users.noreply.github.com> Date: Mon, 23 Jan 2023 20:47:54 -0600 Subject: Task 1 solution --- challenge-201/aut0exec/perl/Task1.pl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 challenge-201/aut0exec/perl/Task1.pl diff --git a/challenge-201/aut0exec/perl/Task1.pl b/challenge-201/aut0exec/perl/Task1.pl new file mode 100644 index 0000000000..5cec6c95bb --- /dev/null +++ b/challenge-201/aut0exec/perl/Task1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +# +# You are given an array of unique numbers. +# Write a script to find out all missing numbers in the range 0..$n where $n is the array size. +# + +use strict; +use warnings; + +#~ my @num_array = (2, 1, 4, 3); +my @num_array = (0, 1, 2, 3, 4); +my $array_len = scalar(@num_array); +my %array_hash = map { $_ => 1 } @num_array; + +print("Array length is: $array_len \n"); + +foreach ( 0..$array_len ){ + #~ print ("Checking $_ \n"); + if (! exists($array_hash{$_})){ + print("Array is missing $_!\n"); + last; + } +} -- cgit