diff options
| author | Nuno Vieira <nunovieira220@gmail.com> | 2020-12-15 01:18:03 +0000 |
|---|---|---|
| committer | Nuno Vieira <nunovieira220@gmail.com> | 2020-12-15 01:18:03 +0000 |
| commit | cb26c8fcfd81f7a07676c40e39b14d04fb43c118 (patch) | |
| tree | ee9c3fbdadf167b96a86b8d9ff5eb9d0391232dc | |
| parent | 05b96afc64fbcae0ef11b10fd4bd60814cc79211 (diff) | |
| download | perlweeklychallenge-club-cb26c8fcfd81f7a07676c40e39b14d04fb43c118.tar.gz perlweeklychallenge-club-cb26c8fcfd81f7a07676c40e39b14d04fb43c118.tar.bz2 perlweeklychallenge-club-cb26c8fcfd81f7a07676c40e39b14d04fb43c118.zip | |
Add nunovieira220 perl solution to challenge 091
| -rw-r--r-- | challenge-091/nunovieira220/perl/ch-1.pl | 27 | ||||
| -rw-r--r-- | challenge-091/nunovieira220/perl/ch-2.pl | 29 |
2 files changed, 56 insertions, 0 deletions
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 |
