aboutsummaryrefslogtreecommitdiff
path: root/challenge-063
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-06-02 02:14:10 +0100
committerGitHub <noreply@github.com>2020-06-02 02:14:10 +0100
commitcf567a97b7cec84f339bbc2a6930164206e5783b (patch)
tree5e0b657375fad5467a6a3d9f63dc5b17ba1e1561 /challenge-063
parent74a5c3e56bf2b7860fc760be32e145516b9c0766 (diff)
parent0f5bdfb7781cc28c490df9f527e86e8515750985 (diff)
downloadperlweeklychallenge-club-cf567a97b7cec84f339bbc2a6930164206e5783b.tar.gz
perlweeklychallenge-club-cf567a97b7cec84f339bbc2a6930164206e5783b.tar.bz2
perlweeklychallenge-club-cf567a97b7cec84f339bbc2a6930164206e5783b.zip
Merge pull request #1784 from jacoby/master
I guess I thought I PRd this previously
Diffstat (limited to 'challenge-063')
-rwxr-xr-xchallenge-063/dave-jacoby/perl/ch-1.pl30
-rwxr-xr-xchallenge-063/dave-jacoby/perl/ch-2.pl34
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-063/dave-jacoby/perl/ch-1.pl b/challenge-063/dave-jacoby/perl/ch-1.pl
new file mode 100755
index 0000000000..be3a29e8e1
--- /dev/null
+++ b/challenge-063/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+
+# USAGE: ch-1.pl [-u] [file ...]
+
+use strict;
+use warnings;
+use utf8;
+use feature qw{ fc postderef say signatures state switch };
+no warnings qw{ experimental };
+
+use Getopt::Long;
+use Carp;
+use JSON;
+
+my $json = JSON->new->canonical->allow_nonref->pretty->space_after;
+
+say last_word();
+say last_word( ' hello world', qr/[ea]l/ ) || 'undef'; # 'hello'
+say last_word( "Don't match too much, Chet!", qr/ch.t/i ) || 'undef'; # 'Chet!'
+say last_word( "spaces in regexp won't match", qr/in re/ ) || 'undef'; # undef
+say last_word( join( ' ', 1 .. 1e6 ), qr/^(3.*?){3}/ ) || 'undef'; # '399933'
+
+sub last_word ( $string = ' strang string', $regex = qr/\w/ ) {
+ my ($output) =
+ reverse
+ grep { /$regex/ }
+ grep { /\S/ }
+ split /\s+/, $string;
+ return $output;
+}
diff --git a/challenge-063/dave-jacoby/perl/ch-2.pl b/challenge-063/dave-jacoby/perl/ch-2.pl
new file mode 100755
index 0000000000..c4413d7d29
--- /dev/null
+++ b/challenge-063/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use utf8;
+use feature qw{ postderef say signatures state switch };
+no warnings qw{ experimental };
+
+use Carp;
+use JSON;
+my $json = JSON->new->canonical->allow_nonref->pretty->space_after;
+
+my $word = 'xyxx';
+
+say rotate_string($word);
+
+sub rotate_string( $word ) {
+ say $word;
+ my $l = length $word;
+ my $c = 0;
+ my $copy = $word;
+ while (1) {
+ my $m = $c % $l;
+ $c++;
+ my @copy = split //, $copy;
+ for ( 0 .. $m ) {
+ push @copy, shift @copy;
+ }
+ $copy = join '', @copy;
+ return $c if $word eq $copy;
+ exit if $c > 10;
+ }
+ return 1;
+}