blob: 088a0586e74168ddf0c2567c3415fd4478a851dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#!/usr/bin/perl
# Challenge 080
#
# TASK #1 > Smallest Positive Number
# Submitted by: Mohammad S Anwar
# You are given unsorted list of integers @N.
#
# Write a script to find out the smallest positive number missing.
#
# Example 1:
# Input: @N = (5, 2, -2, 0)
# Output: 1
# Example 2:
# Input: @N = (1, 8, -1)
# Output: 2
# Example 3:
# Input: @N = (2, 0, -1)
# Output: 1
use Modern::Perl;
say missing(@ARGV);
sub missing {
my @N = sort grep {$_ > 0} @_; # filter only positive numbers and sort
for (0 .. $#N) { # find missing sequence
return $_+1 if $N[$_] != $_+1;
}
return scalar(@N)+1;
}
|