diff options
| -rwxr-xr-x | challenge-262/nelo-tovar/bash/ch-1.sh | 16 | ||||
| -rw-r--r-- | challenge-262/nelo-tovar/perl/ch-1.pl | 5 |
2 files changed, 13 insertions, 8 deletions
diff --git a/challenge-262/nelo-tovar/bash/ch-1.sh b/challenge-262/nelo-tovar/bash/ch-1.sh index c88245da06..f0151dc053 100755 --- a/challenge-262/nelo-tovar/bash/ch-1.sh +++ b/challenge-262/nelo-tovar/bash/ch-1.sh @@ -8,16 +8,22 @@ function max_positive_negative() { local nums=("$@") - locali max=0 + local positive=0 + local negative=0 for i in "${nums[@]}"; do - i=${i#-} - if [ $i -gt $max ]; then - max=$i + if [ $i -ge 0 ]; then + ((positive++)) + else + ((negative++)) fi done - echo $max + if [ $positive -gt $negative ]; then + echo $positive + else + echo $negative + fi } example1='-3 1 2 -1 3 -2 4' diff --git a/challenge-262/nelo-tovar/perl/ch-1.pl b/challenge-262/nelo-tovar/perl/ch-1.pl index 204fe9d74c..ce3e9bf99c 100644 --- a/challenge-262/nelo-tovar/perl/ch-1.pl +++ b/challenge-262/nelo-tovar/perl/ch-1.pl @@ -10,7 +10,6 @@ use strict; use warnings; use v5.28; -use List::Util qw /max min/; use Data::Dump qw(dump); my @examples = ( @@ -21,8 +20,8 @@ my @examples = ( sub max_positive_negative { my $nums = shift; - my $positive = max(grep {$_ >= 0} @$nums); - my $negative = abs(min(grep {$_ < 0 } @$nums)); + my $positive = scalar grep {$_ >= 0} @$nums; + my $negative = scalar grep {$_ < 0 } @$nums; return $positive > $negative ? $positive : $negative; } |
