diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-12-16 04:31:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-16 04:31:33 +0000 |
| commit | 22bec07b028baaa07bec4689d2ef1dd0bf25c2fb (patch) | |
| tree | ebf1b1c3d7ac3fad015491fe1215a12119b6bd99 | |
| parent | a36a0161fefd3dd0b3ed279d7e4fa4719c737410 (diff) | |
| parent | 8ac83d9379f8b1de1acc90ca0efd9cfb62fb6d5b (diff) | |
| download | perlweeklychallenge-club-22bec07b028baaa07bec4689d2ef1dd0bf25c2fb.tar.gz perlweeklychallenge-club-22bec07b028baaa07bec4689d2ef1dd0bf25c2fb.tar.bz2 perlweeklychallenge-club-22bec07b028baaa07bec4689d2ef1dd0bf25c2fb.zip | |
Merge pull request #2991 from wlmb/challenges
Add solutions to challenge 91
| -rw-r--r-- | challenge-091/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-091/wlmb/perl/ch-1.pl | 28 | ||||
| -rwxr-xr-x | challenge-091/wlmb/perl/ch-2.pl | 25 |
3 files changed, 54 insertions, 0 deletions
diff --git a/challenge-091/wlmb/blog.txt b/challenge-091/wlmb/blog.txt new file mode 100644 index 0000000000..7a972b901f --- /dev/null +++ b/challenge-091/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2020/12/14/PWC91/ diff --git a/challenge-091/wlmb/perl/ch-1.pl b/challenge-091/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..96e6d97d94 --- /dev/null +++ b/challenge-091/wlmb/perl/ch-1.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl +# Perl weekly challenge 091 +# Task 1: Count Number +# Simple RLE encoding of a sequence of digits. +# See https:/wlmb.github.io/2020/12/14/PWC91/#task-1-count-number +use warnings; +use strict; +use v5.10; +use List::Util qw(all); +use Scalar::Util::Numeric qw(isint); + +die "Usage ./ch-1.pl n0 n1 ... to codify numbers n0 n1 ..." unless @ARGV; +die "Only non-negative numbers allowed" unless all {isint $_ == 1} @ARGV; + +for my $N(map {int $_} @ARGV){ + print "Input:\t$N\nOutput:\t"; + my $current_digit=""; # Initialize to something printable + my $current_count=""; + foreach(split(//, $N), "I'm not a digit"){ # digits and a unique stop marker + if($current_digit ne $_ || $current_count eq 9){ # string comparisons + print "$current_count$current_digit"; + $current_count=0; + $current_digit=$_; + } + ++$current_count; + } + say "\n"; +} diff --git a/challenge-091/wlmb/perl/ch-2.pl b/challenge-091/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..c117db203c --- /dev/null +++ b/challenge-091/wlmb/perl/ch-2.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +# Perl weekly challenge 091 +# Task 2: Jump Game +# Test if you can reach last element of an array by succesive jumps of bounded lengths. +# See https:/wlmb.github.io/2020/12/14/PWC91/#task-2-jump-game + +use strict; +use warnings; +use v5.10; +use List::Util qw(all); +use Scalar::Util::Numeric qw(isint); + +die "Usage: ./ch-2.pl s0 s1 s2...\n\t with sn maximum number of steps from stone n" + unless @ARGV; +die "Only non-negative numbers allowed" unless all {isint $_ == 1} @ARGV; +my @stones=@ARGV; + +my @stepping_stones; +push @stepping_stones, $#stones; +foreach(reverse (0..$#stones-1)){ # add stepping stones from right to left + unshift @stepping_stones, $_ if $stepping_stones[0] <= $_+$stones[$_]; +} +say $stepping_stones[0]==0 + ?"1 Success\nPath: " . join "->", @stepping_stones + :"0 Failure"; |
