diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-09-29 20:43:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-29 20:43:41 +0100 |
| commit | 501de8433e258e37f4d423bb3f4f89b85222f4ce (patch) | |
| tree | 732872b2f01f9118e2fd3e085986a1d07c43182d /challenge-080 | |
| parent | a26ca3a0677b55d0f83bccc8979e2be5e2df41c7 (diff) | |
| parent | 99fc28fb74792d2f7d455c39b50e72041b1cb04d (diff) | |
| download | perlweeklychallenge-club-501de8433e258e37f4d423bb3f4f89b85222f4ce.tar.gz perlweeklychallenge-club-501de8433e258e37f4d423bb3f4f89b85222f4ce.tar.bz2 perlweeklychallenge-club-501de8433e258e37f4d423bb3f4f89b85222f4ce.zip | |
Merge pull request #2411 from nunovieira220/challenge-080
Add solution to challenge 080
Diffstat (limited to 'challenge-080')
| -rw-r--r-- | challenge-080/nunovieira220/js/ch-1.js | 11 | ||||
| -rw-r--r-- | challenge-080/nunovieira220/js/ch-2.js | 13 | ||||
| -rw-r--r-- | challenge-080/nunovieira220/perl/ch-1.pl | 20 | ||||
| -rw-r--r-- | challenge-080/nunovieira220/perl/ch-2.pl | 20 |
4 files changed, 64 insertions, 0 deletions
diff --git a/challenge-080/nunovieira220/js/ch-1.js b/challenge-080/nunovieira220/js/ch-1.js new file mode 100644 index 0000000000..0f9036178c --- /dev/null +++ b/challenge-080/nunovieira220/js/ch-1.js @@ -0,0 +1,11 @@ +// Input +const A = [5, 2, -2, 0]; + +// Smallest positive number bits +const flags = [1]; + +A.forEach(n => { + if(n >= 0) flags[n] = 1; +}); + +console.log(flags.findIndex(Object.is.bind(null, undefined)));
\ No newline at end of file diff --git a/challenge-080/nunovieira220/js/ch-2.js b/challenge-080/nunovieira220/js/ch-2.js new file mode 100644 index 0000000000..d942aac84d --- /dev/null +++ b/challenge-080/nunovieira220/js/ch-2.js @@ -0,0 +1,13 @@ +// Input +const A = [1, 4, 3, 2]; + +// Count candies +let counter = A.length; + +A.push(Number.MAX_SAFE_INTEGER); + +for (let i = A.length - 1; i >= 0; i--) { + counter += (A[i] > A[i-1]) + (A[i] > A[i+1]); +} + +console.log(counter);
\ No newline at end of file diff --git a/challenge-080/nunovieira220/perl/ch-1.pl b/challenge-080/nunovieira220/perl/ch-1.pl new file mode 100644 index 0000000000..5757a5dd88 --- /dev/null +++ b/challenge-080/nunovieira220/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use List::Util qw(first); + +# Input +my @A = @ARGV || (5, 2, -2, 0); + +# Smallest positive number bits +my @flags = (); + +for (@A) { + $flags[$_] = 1 if($_ >= 0); +} + +my $res = first { !defined($flags[$_]) } 1..$#flags; + +# Output +print $res."\n";
\ No newline at end of file diff --git a/challenge-080/nunovieira220/perl/ch-2.pl b/challenge-080/nunovieira220/perl/ch-2.pl new file mode 100644 index 0000000000..c5314d8d54 --- /dev/null +++ b/challenge-080/nunovieira220/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +# Input +my @A = @ARGV || (1, 4, 3, 2); + +# Count candies +my $len = scalar @A; +my $counter = $len; + +push @A, ~0; + +for (my $i = $len - 1; $i >= 0; $i--) { + $counter += ($A[$i] > $A[$i-1]) + ($A[$i] > $A[$i+1]); +} + +# Output +print $counter."\n";
\ No newline at end of file |
