diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-12-16 04:44:28 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-16 04:44:28 +0000 |
| commit | 1fa44b9f3d7b5224459c8114bf64fd3230216950 (patch) | |
| tree | 401c428b09a6b9982f58de37645b1bafe9e6c92d | |
| parent | cd83c727816d15cb98b406a85eaa9438e24dc6e9 (diff) | |
| parent | 8c297853bfe508c51a73b6ab2ea41dc5ff547edf (diff) | |
| download | perlweeklychallenge-club-1fa44b9f3d7b5224459c8114bf64fd3230216950.tar.gz perlweeklychallenge-club-1fa44b9f3d7b5224459c8114bf64fd3230216950.tar.bz2 perlweeklychallenge-club-1fa44b9f3d7b5224459c8114bf64fd3230216950.zip | |
Merge pull request #2994 from nunovieira220/challenge-091
Add solution to challenge 091
| -rw-r--r-- | challenge-091/nunovieira220/js/ch-1.js | 21 | ||||
| -rw-r--r-- | challenge-091/nunovieira220/js/ch-2.js | 24 | ||||
| -rw-r--r-- | challenge-091/nunovieira220/perl/ch-1.pl | 27 | ||||
| -rw-r--r-- | challenge-091/nunovieira220/perl/ch-2.pl | 29 |
4 files changed, 101 insertions, 0 deletions
diff --git a/challenge-091/nunovieira220/js/ch-1.js b/challenge-091/nunovieira220/js/ch-1.js new file mode 100644 index 0000000000..eda923eea7 --- /dev/null +++ b/challenge-091/nunovieira220/js/ch-1.js @@ -0,0 +1,21 @@ +// Input +const N = 2333445; + +// Count Number +const S = N.toString(); +let res = ""; +let last = S.substring(0, 1); +let counter = 1; + +for (const C of S.substring(1, S.length)) { + if(C != last) { + res += counter+last; + counter = 0; + last = C; + } + + counter++; +} + +// Output +console.log(res + counter + last);
\ No newline at end of file diff --git a/challenge-091/nunovieira220/js/ch-2.js b/challenge-091/nunovieira220/js/ch-2.js new file mode 100644 index 0000000000..a0bb175f1b --- /dev/null +++ b/challenge-091/nunovieira220/js/ch-2.js @@ -0,0 +1,24 @@ +// Input +const A = [2, 1, 3, 0, 3, 1, 5, 0, 0, 0, 0, 2]; + +// Jump Game +if (A.length <= 1) { + console.log(1); + exit(0); +} + +const targets = {}; +targets[A.length - 1] = 1; + +for(let i = A.length - 2; i > 0; i--) { + const jump = i + A[i]; + + if (targets[jump]) { + targets[i] = 1; + } +} + +const res = targets[A[0]] ? 1 : 0; + +// Output +console.log(res);
\ No newline at end of file diff --git a/challenge-091/nunovieira220/perl/ch-1.pl b/challenge-091/nunovieira220/perl/ch-1.pl new file mode 100644 index 0000000000..d1cd32f232 --- /dev/null +++ b/challenge-091/nunovieira220/perl/ch-1.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature qw(say); + +# Input +my $N = 2333445; + +# Count Number +my $S = "$N"; +my $res = ""; +my $last = substr($S, 0, 1); +my $counter = 1; + +foreach my $C (split //, substr($S, 1, length($S))) { + if($C != $last) { + $res .= $counter.$last; + $counter = 0; + $last = $C; + } + + $counter++; +} + +# Output +say ($res, $counter, $last);
\ No newline at end of file diff --git a/challenge-091/nunovieira220/perl/ch-2.pl b/challenge-091/nunovieira220/perl/ch-2.pl new file mode 100644 index 0000000000..97cfb738be --- /dev/null +++ b/challenge-091/nunovieira220/perl/ch-2.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature qw(say); + +# Input +my @A = (2, 1, 1, 0, 2); + +# Jump Game +my $len = scalar @A; + +if ($len <= 1) { + say 1; + exit; +} + +my %targets = ($len - 1, 1); + +for(my $i = $len - 2; $i > 0; $i--) { + my $jump = $i + $A[$i]; + + $targets{$i} = 1 if (defined $targets{$jump}); +} + +my $res = defined $targets{$A[0]} ? 1 : 0; + +# Output +say $res;
\ No newline at end of file |
