From 7793bc662990cc8e4ee41a40dee90782cd82aa5f Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Wed, 21 Oct 2020 20:47:17 +0100 Subject: Add nunovieira220 perl solution to challenge 083 --- challenge-083/nunovieira220/perl/ch-1.pl | 14 ++++++++++++++ challenge-083/nunovieira220/perl/ch-2.pl | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 challenge-083/nunovieira220/perl/ch-1.pl create mode 100644 challenge-083/nunovieira220/perl/ch-2.pl 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 -- cgit From f2286e4478f6fef41a08d00bac2ae6659f2c08b7 Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Wed, 21 Oct 2020 20:47:29 +0100 Subject: Add nunovieira220 js solution to challenge 083 --- challenge-083/nunovieira220/js/ch-1.js | 7 +++++++ challenge-083/nunovieira220/js/ch-2.js | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 challenge-083/nunovieira220/js/ch-1.js create mode 100644 challenge-083/nunovieira220/js/ch-2.js 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 -- cgit