diff options
| -rw-r--r-- | challenge-099/nunovieira220/js/ch-1.js | 10 | ||||
| -rw-r--r-- | challenge-099/nunovieira220/js/ch-2.js | 18 | ||||
| -rw-r--r-- | challenge-099/nunovieira220/perl/ch-1.pl | 18 | ||||
| -rw-r--r-- | challenge-099/nunovieira220/perl/ch-2.pl | 25 |
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)); +} |
