From cb26c8fcfd81f7a07676c40e39b14d04fb43c118 Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Tue, 15 Dec 2020 01:18:03 +0000 Subject: Add nunovieira220 perl solution to challenge 091 --- challenge-091/nunovieira220/perl/ch-1.pl | 27 +++++++++++++++++++++++++++ challenge-091/nunovieira220/perl/ch-2.pl | 29 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 challenge-091/nunovieira220/perl/ch-1.pl create mode 100644 challenge-091/nunovieira220/perl/ch-2.pl 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 -- cgit From 8c297853bfe508c51a73b6ab2ea41dc5ff547edf Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Tue, 15 Dec 2020 01:18:16 +0000 Subject: Add nunovieira220 js solution to challenge 091 --- challenge-091/nunovieira220/js/ch-1.js | 21 +++++++++++++++++++++ challenge-091/nunovieira220/js/ch-2.js | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 challenge-091/nunovieira220/js/ch-1.js create mode 100644 challenge-091/nunovieira220/js/ch-2.js 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 -- cgit