aboutsummaryrefslogtreecommitdiff
path: root/challenge-321/mahnkong/perl/ch-2.pl
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-321/mahnkong/perl/ch-2.pl')
-rw-r--r--challenge-321/mahnkong/perl/ch-2.pl24
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-321/mahnkong/perl/ch-2.pl b/challenge-321/mahnkong/perl/ch-2.pl
new file mode 100644
index 0000000000..0f0aa596c6
--- /dev/null
+++ b/challenge-321/mahnkong/perl/ch-2.pl
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub analyze($str) {
+ my @buffer;
+ foreach my $c (split //, $str) {
+ if ($c eq '#') {
+ pop @buffer if scalar(@buffer) > 0;
+ } else {
+ push @buffer, $c;
+ }
+ }
+ return join('', @buffer);
+}
+
+sub run($str1, $str2) {
+ return analyze($str1) eq analyze($str2) ? 1 : 0;
+}
+
+is(run("ab#c", "ad#c"), 1, "Example 1");
+is(run("ab##", "a#b#"), 1, "Example 1");
+is(run("a#b", "c"), 0, "Example 1");