diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-02-09 22:25:46 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-09 22:25:46 +0000 |
| commit | eb384dda1ac4923971572a9e3da57b84e79e8f43 (patch) | |
| tree | 3aaaac393e6f6f4e0ae87c24566ff1f950b787fa | |
| parent | f84686074d2aa6838c209b09c1097a933a421442 (diff) | |
| parent | e0a08dc6aac020ba84e5f6b2be937173229396a0 (diff) | |
| download | perlweeklychallenge-club-eb384dda1ac4923971572a9e3da57b84e79e8f43.tar.gz perlweeklychallenge-club-eb384dda1ac4923971572a9e3da57b84e79e8f43.tar.bz2 perlweeklychallenge-club-eb384dda1ac4923971572a9e3da57b84e79e8f43.zip | |
Merge pull request #3484 from stuart-little/stuart-little_099_perl
1st commit on 099_perl
| -rwxr-xr-x | challenge-099/stuart-little/perl/ch-1.pl | 11 | ||||
| -rwxr-xr-x | challenge-099/stuart-little/perl/ch-2.pl | 29 |
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-099/stuart-little/perl/ch-1.pl b/challenge-099/stuart-little/perl/ch-1.pl new file mode 100755 index 0000000000..81188aef92 --- /dev/null +++ b/challenge-099/stuart-little/perl/ch-1.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl +use warnings; +use v5.12; + +# run <script> <string> <pattern> + +use feature qw(signatures); +no warnings qw(experimental::signatures); + +my $pat = '^' . (($ARGV[1] =~ s/\*/.*/gr) =~ s/\?/./gr) . '$'; +say my $res = (($ARGV[0] =~ /$pat/) ? (1) : (0)); diff --git a/challenge-099/stuart-little/perl/ch-2.pl b/challenge-099/stuart-little/perl/ch-2.pl new file mode 100755 index 0000000000..a806719776 --- /dev/null +++ b/challenge-099/stuart-little/perl/ch-2.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl +use warnings; +use v5.12; + +# run <script> <string1> <string2> + +use feature qw(signatures); +no warnings qw(experimental::signatures); + +sub occ($ar1, $ar2) { + (scalar @{$ar2} == 0) && return 1; + (scalar @{$ar1} == 0) && return 0; + + my @short_ar2=$ar2->@[1..scalar @{$ar2}-1]; + my $sum=0; + my @arrs = + map {my @a = $ar1->@[$_+1..scalar @{$ar1}-1]; \@a} + grep {$ar1->[$_] eq $ar2->[0]} + keys(@{$ar1}); + + for (@arrs) { + $sum += occ($_,\@short_ar2); + } + return $sum; +} + +my ($ar1,$ar2) = map {my @a = split(//,$_); \@a} @ARGV[0,1]; + +say occ($ar1,$ar2); |
