diff options
| author | boblied <boblied@gmail.com> | 2020-10-25 11:04:31 -0500 |
|---|---|---|
| committer | boblied <boblied@gmail.com> | 2020-10-25 11:04:31 -0500 |
| commit | c2cca27cbd85410a13d1291f223786d2a7ec96e5 (patch) | |
| tree | c847c32942c0fc77710afc9e0e775364ee4daba5 | |
| parent | 2cdf46aacae1e1fa62e70bc7553f546119ca02d4 (diff) | |
| download | perlweeklychallenge-club-c2cca27cbd85410a13d1291f223786d2a7ec96e5.tar.gz perlweeklychallenge-club-c2cca27cbd85410a13d1291f223786d2a7ec96e5.tar.bz2 perlweeklychallenge-club-c2cca27cbd85410a13d1291f223786d2a7ec96e5.zip | |
Update README README
| -rw-r--r-- | challenge-083/bob-lied/README | 4 | ||||
| -rwxr-xr-x | challenge-083/bob-lied/perl/ch-2.pl | 51 |
2 files changed, 53 insertions, 2 deletions
diff --git a/challenge-083/bob-lied/README b/challenge-083/bob-lied/README index 4c6cdb786b..be9398e9a3 100644 --- a/challenge-083/bob-lied/README +++ b/challenge-083/bob-lied/README @@ -1,3 +1,3 @@ -Solutions to weekly challenge 82 by Bob Lied. +Solutions to weekly challenge 83 by Bob Lied. -https://perlweeklychallenge.org/blog/perl-weekly-challenge-082/ +https://perlweeklychallenge.org/blog/perl-weekly-challenge-083/ diff --git a/challenge-083/bob-lied/perl/ch-2.pl b/challenge-083/bob-lied/perl/ch-2.pl new file mode 100755 index 0000000000..ae27fcb96d --- /dev/null +++ b/challenge-083/bob-lied/perl/ch-2.pl @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# ch-2.pl +#============================================================================= +# Copyright (c) 2020, Bob Lied +#============================================================================= +# Perl Weekly Challenge 083 Task #2 > Flip Array +#============================================================================= +# You are given an array @A of positive numbers. +# Write a script to flip the sign of some members of the given array so that +# the sum of the all members is minimum non-negative. +# Given an array of positive elements, you have to flip the sign of some of +# its elements such that the resultant sum of the elements of array should be +# minimum non-negative(as close to zero as possible). Return the minimum no. +# of elements whose sign needs to be flipped such that the resultant sum is +# minimum non-negative. +# Example 1: Input: @A = (3, 10, 8) Output: 1 +# Explanation: Flipping the sign of just one element 10 gives the result 1 i.e. +# (3) + (-10) + (8) = 1 +# +# Example 2: Input: @A = (12, 2, 10) Output: 1 +# Explanation: Flipping the sign of just one element 12 gives the result 0 i.e. +# (-12) + (2) + (10) = 0 + +use strict; +use warnings; +use v5.30; + +use feature qw/ signatures /; +no warnings qw/ experimental::signatures /; + +use Getopt::Long; + +use lib "lib"; +use Task2; + +sub Usage { "Usage: $0 args" }; + +my $Verbose = 0; +GetOptions('verbose' => \$Verbose); + +my $arg = shift; +my @list = @ARGV; + +die Usage() unless $arg; +die Usage() unless @list; + +my $task = Task2->new(); +my $result = $task->run(); +say $result; |
