aboutsummaryrefslogtreecommitdiff
path: root/challenge-082/juliodcs
diff options
context:
space:
mode:
authorjuliodcs <julio.dcs@gmail.com>2020-10-17 01:04:48 +0200
committerjuliodcs <julio.dcs@gmail.com>2020-10-17 01:04:48 +0200
commitd198f9c1f1477ca6a02f67dade78b846fff54d02 (patch)
treeb5570b1af562c3735017f44bf8a705ad321f7966 /challenge-082/juliodcs
parentd04340bbc0ff6dc42a4fe2fc6cc849ff4bc53c66 (diff)
downloadperlweeklychallenge-club-d198f9c1f1477ca6a02f67dade78b846fff54d02.tar.gz
perlweeklychallenge-club-d198f9c1f1477ca6a02f67dade78b846fff54d02.tar.bz2
perlweeklychallenge-club-d198f9c1f1477ca6a02f67dade78b846fff54d02.zip
Fix case when a=b
Diffstat (limited to 'challenge-082/juliodcs')
-rw-r--r--challenge-082/juliodcs/perl/ch-2.pl3
-rw-r--r--challenge-082/juliodcs/raku/ch-2.raku9
2 files changed, 7 insertions, 5 deletions
diff --git a/challenge-082/juliodcs/perl/ch-2.pl b/challenge-082/juliodcs/perl/ch-2.pl
index 5e6398cfdf..e21df5eee7 100644
--- a/challenge-082/juliodcs/perl/ch-2.pl
+++ b/challenge-082/juliodcs/perl/ch-2.pl
@@ -4,9 +4,10 @@ use experimental 'signatures';
use feature 'say';
sub interleaved($a, $b, $c) {
+ ($a, $b) = ($b, $a) if length $a < length $b;
my ($is_a, $is_b) = (0, 0);
$c =~ s/(\Q$a\E)|\Q$b\E/ $1 and ++$is_a or ++$is_b; '' /e for 1 .. 2;
- $c eq q() && $is_a && $is_b
+ $c eq q() && ($is_a && $is_b || $a eq $b)
}
say interleaved(@ARGV) ? 1 : 0;
diff --git a/challenge-082/juliodcs/raku/ch-2.raku b/challenge-082/juliodcs/raku/ch-2.raku
index 2821998f72..ad7c3388f9 100644
--- a/challenge-082/juliodcs/raku/ch-2.raku
+++ b/challenge-082/juliodcs/raku/ch-2.raku
@@ -1,9 +1,10 @@
#!/usr/bin/env raku
-sub interleaved($a, $b, $c is rw) {
- my ($is_a, $is_b) = 0, 0;
- $c ~~ s/($a)|$b/{ $0 and ++$is_a or ++$is_b; 「」 }/ for ^2;
- +($c eq 「」 && $is_a && $is_b)
+sub interleaved($a is rw, $b is rw, $c is rw) {
+ ($a, $b) .= reverse if $a.chars < $b.chars;
+ my ($has-a, $has-b) = False, False;
+ $c ~~ s/ $a {$has-a = True} | $b {$has-b = True} // for ^2;
+ +($c eq 「」 && ($has-a && $has-b || $a eq $b))
}
say interleaved |@*ARGS;