aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-12-16 04:48:29 +0000
committerGitHub <noreply@github.com>2020-12-16 04:48:29 +0000
commitd6a8a114ee7b43811353638b580b1f429a6a6c7a (patch)
tree56ec9c463ed9462b43dc67fe19ae2fc94a61be04
parent690e8fd0339456739a5fd9dd14b385d8b3ed3ff1 (diff)
parent71c43e79d03679056e97d698f3e452729dcf0759 (diff)
downloadperlweeklychallenge-club-d6a8a114ee7b43811353638b580b1f429a6a6c7a.tar.gz
perlweeklychallenge-club-d6a8a114ee7b43811353638b580b1f429a6a6c7a.tar.bz2
perlweeklychallenge-club-d6a8a114ee7b43811353638b580b1f429a6a6c7a.zip
Merge pull request #2996 from polettix/polettix/pwc091
Add polettix's solution to PWC091
-rw-r--r--challenge-091/polettix/blog.txt1
-rw-r--r--challenge-091/polettix/blog1.txt1
-rw-r--r--challenge-091/polettix/perl/ch-1.pl34
-rw-r--r--challenge-091/polettix/perl/ch-2.pl14
4 files changed, 50 insertions, 0 deletions
diff --git a/challenge-091/polettix/blog.txt b/challenge-091/polettix/blog.txt
new file mode 100644
index 0000000000..8a0c74e5c9
--- /dev/null
+++ b/challenge-091/polettix/blog.txt
@@ -0,0 +1 @@
+https://github.polettix.it/ETOOBUSY/2020/12/15/pwc091-count-number/
diff --git a/challenge-091/polettix/blog1.txt b/challenge-091/polettix/blog1.txt
new file mode 100644
index 0000000000..7de637fc35
--- /dev/null
+++ b/challenge-091/polettix/blog1.txt
@@ -0,0 +1 @@
+https://github.polettix.it/ETOOBUSY/2020/12/16/jump-game/
diff --git a/challenge-091/polettix/perl/ch-1.pl b/challenge-091/polettix/perl/ch-1.pl
new file mode 100644
index 0000000000..30abdd0ef2
--- /dev/null
+++ b/challenge-091/polettix/perl/ch-1.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/env perl
+use 5.024;
+use warnings;
+use experimental qw< postderef signatures >;
+no warnings qw< experimental::postderef experimental::signatures >;
+
+sub count_number ($N) {
+ my $retval = '';
+ while (length $N) {
+ my ($sequence, $char) = $N =~ m{((.)\2*)}mxs;
+ my $n = length $sequence;
+ $retval .= $n . $char;
+ substr $N, 0, $n, '';
+ }
+ return $retval;
+}
+
+sub count_number_2 ($N) {
+ my $len = length $N;
+ my ($retval, $previous, $count) = ('', '', 0);
+ for my $i (0 .. $len) {
+ my $c = $i < $len ? substr($N, $i, 1) : '';
+ if ($c eq $previous) { ++$count }
+ else {
+ $retval .= $count . $previous if $count;
+ ($previous, $count) = ($c, 1);
+ }
+ }
+ return $retval;
+}
+
+my $input = shift // '1122234';
+say count_number($input);
+say count_number_2($input);
diff --git a/challenge-091/polettix/perl/ch-2.pl b/challenge-091/polettix/perl/ch-2.pl
new file mode 100644
index 0000000000..c3759fd93f
--- /dev/null
+++ b/challenge-091/polettix/perl/ch-2.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+use 5.024;
+use warnings;
+use experimental qw< postderef signatures >;
+no warnings qw< experimental::postderef experimental::signatures >;
+
+sub jump_game ($N) {
+ my $position = 0;
+ $position += $N->[$position] while $position < $#$N && $N->[$position];
+ return $position == $#$N ? 1 : 0;
+}
+
+my @sequence = @ARGV ? @ARGV : (1, 2, 1, 2);
+say jump_game(\@sequence);