aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-02-14 03:59:50 +0000
committerGitHub <noreply@github.com>2021-02-14 03:59:50 +0000
commit3460a0dd47fb228688c295caf48b9c1056c3caa0 (patch)
tree1ba33ed6be693a9dfc2e718a8b86da7376e6b9db
parentb3daee64ed733af78f2141d074fcc8ace8071ea2 (diff)
parent05840b155c26bc3de273894a8d96f3cf8afb7952 (diff)
downloadperlweeklychallenge-club-3460a0dd47fb228688c295caf48b9c1056c3caa0.tar.gz
perlweeklychallenge-club-3460a0dd47fb228688c295caf48b9c1056c3caa0.tar.bz2
perlweeklychallenge-club-3460a0dd47fb228688c295caf48b9c1056c3caa0.zip
Merge pull request #3509 from LubosKolouch/master
Challenge 099 LK Perl
-rw-r--r--challenge-099/lubos-kolouch/perl/ch-1.pl39
-rw-r--r--challenge-099/lubos-kolouch/perl/ch-2.pl40
2 files changed, 79 insertions, 0 deletions
diff --git a/challenge-099/lubos-kolouch/perl/ch-1.pl b/challenge-099/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..34d56af204
--- /dev/null
+++ b/challenge-099/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+#===============================================================================
+#
+# FILE: ch-1.pl
+#
+# USAGE: ./ch-1.pl
+#
+# DESCRIPTION: Perl Weekly Challenge
+# https://www.perlweeklychallenge.org
+# Task 1 - Pattern Match
+#
+# AUTHOR: YOUR NAME (),
+# CREATED: 02/13/2021 12:22:27 PM
+#===============================================================================
+
+use strict;
+use warnings;
+
+sub pattern_match {
+ my $what = shift;
+
+ # convert the pattern to regex
+ $what->{p} =~ s/\?/./g;
+ $what->{p} =~ s/\*/.*/g;
+ $what->{p} = '^'.$what->{p}.'$';
+
+ my $match = $what->{s} =~ /$what->{p}/;
+ return 0 unless $match;
+ return 1;
+}
+
+use Test::More;
+
+is(pattern_match({'s' => 'abcde', 'p' => 'a*e'}), 1);
+is(pattern_match({'s' => 'abcde', 'p' => 'a*d'}), 0);
+is(pattern_match({'s' => 'abcde', 'p' => '?b*d'}), 0);
+is(pattern_match({'s' => 'abcde', 'p' => 'a*c?e'}), 1);
+
+done_testing;
diff --git a/challenge-099/lubos-kolouch/perl/ch-2.pl b/challenge-099/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..450e3576c7
--- /dev/null
+++ b/challenge-099/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+#===============================================================================
+#
+# FILE: ch-2.pl
+#
+# USAGE: ./ch-2.pl
+#
+# DESCRIPTION: Perl Weekly Challenge
+# https://www.perlweeklychallenge.org
+# Task 1 - Unique Subsequence
+#
+# AUTHOR: Lubos Kolouch
+# CREATED: 02/13/2021 12:22:27 PM
+#===============================================================================
+
+use strict;
+use warnings;
+use feature qw/say/;
+
+#FIXME: This does not work
+
+sub unique_subsequences {
+ my $what = shift;
+
+ # let's change the pattern a bit
+ my $mod_pattern = $what->{t};
+ $mod_pattern =~ s/(.)/$1\(\?=.*/g;
+ $mod_pattern .= ')' x length($what->{t});
+ say $mod_pattern;
+
+ my @matches = ($what->{s} =~ m/($mod_pattern)/g);
+ say for @matches;
+ say scalar @matches;
+ return 1;
+}
+
+use Test::More;
+is(unique_subsequences({'s' => 'littleit', 't' => 'lit'}), 1);
+
+done_testing;