45 lines
865 B
Perl
Executable file
45 lines
865 B
Perl
Executable file
#!/usr/bin/env perl
|
|
|
|
#use Modern::Perl;
|
|
use strict;
|
|
use warnings;
|
|
use List::Util qw( reduce );
|
|
|
|
my @array_in = ();
|
|
while (<STDIN>) {
|
|
chomp($_);
|
|
last if ($_ eq '');
|
|
push(@array_in, $_);
|
|
}
|
|
|
|
foreach (@array_in) {
|
|
printf "%s\n", $_;
|
|
}
|
|
|
|
print "Array in is @array_in\n";
|
|
|
|
get_smallest_missing(@array_in);
|
|
|
|
sub get_smallest_missing {
|
|
my (@numbers_array) = @_;
|
|
my $integer = 0;
|
|
|
|
# If 1 is not present in the array it is the lowest integer not in the array
|
|
if ( ! grep( /1/, @numbers_array ) ) {
|
|
print "1 is not in the array, it is the lowest integer not in array\n";
|
|
$integer = 1;
|
|
return $integer;
|
|
}
|
|
else {
|
|
|
|
$integer =
|
|
reduce { $numbers_array[$a] <= $numbers_array[$b] ? $a : $b }
|
|
grep { $numbers_array[$_] >= 2 }
|
|
0..$#numbers_array;
|
|
|
|
print "Returning integer $integer\n";
|
|
|
|
return $integer;
|
|
|
|
}
|
|
}
|