aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-02-12 06:40:45 +0000
committerGitHub <noreply@github.com>2021-02-12 06:40:45 +0000
commit4b891a8dcdc6817c718622369e2c4a0417c029ca (patch)
tree520b24a2f4391b478438a1fe925d1e463023501a
parentf589766d17599cb8a54ed9cd8d56fc58273da494 (diff)
parent9609f2e04ee3392b068f5200c3beaddec432df6c (diff)
downloadperlweeklychallenge-club-4b891a8dcdc6817c718622369e2c4a0417c029ca.tar.gz
perlweeklychallenge-club-4b891a8dcdc6817c718622369e2c4a0417c029ca.tar.bz2
perlweeklychallenge-club-4b891a8dcdc6817c718622369e2c4a0417c029ca.zip
Merge pull request #3501 from nunovieira220/challenge-099
Add solution to challenge 099
-rw-r--r--challenge-099/nunovieira220/js/ch-1.js10
-rw-r--r--challenge-099/nunovieira220/js/ch-2.js18
-rw-r--r--challenge-099/nunovieira220/perl/ch-1.pl18
-rw-r--r--challenge-099/nunovieira220/perl/ch-2.pl25
4 files changed, 71 insertions, 0 deletions
diff --git a/challenge-099/nunovieira220/js/ch-1.js b/challenge-099/nunovieira220/js/ch-1.js
new file mode 100644
index 0000000000..5e41fd4c11
--- /dev/null
+++ b/challenge-099/nunovieira220/js/ch-1.js
@@ -0,0 +1,10 @@
+// Input
+const S = 'abcde';
+const P = 'a*c?e';
+
+// Pattern Match
+const regex = P.replace(/(\?|\*)/g, '.$1');
+const res = S.match(new RegExp(`^${regex}$`, "g"));
+
+// Output
+console.log(res ? 1 : 0);
diff --git a/challenge-099/nunovieira220/js/ch-2.js b/challenge-099/nunovieira220/js/ch-2.js
new file mode 100644
index 0000000000..368b8a3fce
--- /dev/null
+++ b/challenge-099/nunovieira220/js/ch-2.js
@@ -0,0 +1,18 @@
+// Unique Subsequence
+const counter = (S, T) => {
+ if(!T.length || !S.length) return 0;
+
+ const index = S.indexOf(T.substring(0, 1));
+ const last = T.length === 1 ? 1 : 0;
+
+ if(index === -1) return 0;
+
+ return last + counter(S.substring(index + 1), T) + counter(S.substring(index + 1), T.substring(1));
+}
+
+// Input
+const S = 'littleit';
+const T = 'lit';
+
+// Output
+console.log(counter(S, T));
diff --git a/challenge-099/nunovieira220/perl/ch-1.pl b/challenge-099/nunovieira220/perl/ch-1.pl
new file mode 100644
index 0000000000..9f4be9dc9c
--- /dev/null
+++ b/challenge-099/nunovieira220/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+
+# Input
+my $S = "abcde";
+my $P = "a*c?e";
+
+# Pattern Match
+$P =~ s/(\?|\*)/\.$1/g;
+
+my $res = 0;
+$res = 1 if ($S =~ m/^${P}$/);
+
+# Output
+say($res);
diff --git a/challenge-099/nunovieira220/perl/ch-2.pl b/challenge-099/nunovieira220/perl/ch-2.pl
new file mode 100644
index 0000000000..86a27b3db4
--- /dev/null
+++ b/challenge-099/nunovieira220/perl/ch-2.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+
+# Input
+my $S = "littleit";
+my $T = "lit";
+
+# Output
+say(counter($S, $T));
+
+# Unique Subsequence
+sub counter {
+ my ($S, $T) = @_;
+
+ return 0 if(!length($T) || !length($S));
+
+ my $index = index($S, substr($T, 0, 1));
+ my $last = length($T) == 1 ? 1 : 0;
+
+ return 0 if($index == -1);
+ return $last + counter(substr($S, $index + 1), $T) + counter(substr($S, $index + 1), substr($T, 1));
+}