aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-10-21 22:47:07 +0100
committerGitHub <noreply@github.com>2020-10-21 22:47:07 +0100
commit7db35fe95b75c755d0d4edb6c85c5ef68e89277f (patch)
tree073aa6919cde3f9ea965ca728cdb7855139890e5
parent4ac8964e99ddcddbb76e7ad6486737472264637a (diff)
parentf2286e4478f6fef41a08d00bac2ae6659f2c08b7 (diff)
downloadperlweeklychallenge-club-7db35fe95b75c755d0d4edb6c85c5ef68e89277f.tar.gz
perlweeklychallenge-club-7db35fe95b75c755d0d4edb6c85c5ef68e89277f.tar.bz2
perlweeklychallenge-club-7db35fe95b75c755d0d4edb6c85c5ef68e89277f.zip
Merge pull request #2592 from nunovieira220/challenge-083
Add solution to challenge 083
-rw-r--r--challenge-083/nunovieira220/js/ch-1.js7
-rw-r--r--challenge-083/nunovieira220/js/ch-2.js18
-rw-r--r--challenge-083/nunovieira220/perl/ch-1.pl14
-rw-r--r--challenge-083/nunovieira220/perl/ch-2.pl24
4 files changed, 63 insertions, 0 deletions
diff --git a/challenge-083/nunovieira220/js/ch-1.js b/challenge-083/nunovieira220/js/ch-1.js
new file mode 100644
index 0000000000..92635f0ba7
--- /dev/null
+++ b/challenge-083/nunovieira220/js/ch-1.js
@@ -0,0 +1,7 @@
+// Input
+const S = 'The purpose of our lives is to be happy';
+
+// Output
+const res = S.replace(/^[^\s]+\s(.*)\s[^\s]+$/, '$1').replace(/ /g, '');
+
+console.log(res.length); \ No newline at end of file
diff --git a/challenge-083/nunovieira220/js/ch-2.js b/challenge-083/nunovieira220/js/ch-2.js
new file mode 100644
index 0000000000..2b6611f631
--- /dev/null
+++ b/challenge-083/nunovieira220/js/ch-2.js
@@ -0,0 +1,18 @@
+// Input
+const A = [12, 2, 10];
+
+// Flip Array
+let sums = [0];
+
+A.forEach(val => {
+ const arr = [];
+
+ sums.forEach(sum => arr.push(sum + val, sum - val));
+
+ sums = arr;
+});
+
+const res = sums.filter(sum => sum >= 0).sort((a, b) => a - b);
+
+// Output
+console.log(res[0]); \ No newline at end of file
diff --git a/challenge-083/nunovieira220/perl/ch-1.pl b/challenge-083/nunovieira220/perl/ch-1.pl
new file mode 100644
index 0000000000..869f26be00
--- /dev/null
+++ b/challenge-083/nunovieira220/perl/ch-1.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+
+# Input
+my $S = "The purpose of our lives is to be happy";
+
+# Output
+$S =~ s/^[^\s]+\s(.*)\s[^\s]+$/$1/;
+$S =~ s/\s//g;
+
+say length($S); \ No newline at end of file
diff --git a/challenge-083/nunovieira220/perl/ch-2.pl b/challenge-083/nunovieira220/perl/ch-2.pl
new file mode 100644
index 0000000000..4ac4eefaec
--- /dev/null
+++ b/challenge-083/nunovieira220/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+
+# Input
+my @A = (3, 10, 8);
+
+# Flip Array
+my @sums = (0);
+
+for my $val (@A) {
+ my @arr = ();
+
+ push @arr, ($_ + $val, $_ - $val) for (@sums);
+
+ @sums = @arr;
+}
+
+my @res = grep { $_ >= 0 } sort { $a <=> $b } @sums;
+
+# Output
+say $res[0]; \ No newline at end of file