aboutsummaryrefslogtreecommitdiff
path: root/challenge-082/juliodcs
diff options
context:
space:
mode:
authorjuliodcs <julio.dcs@gmail.com>2020-10-17 01:16:31 +0200
committerjuliodcs <julio.dcs@gmail.com>2020-10-17 01:16:31 +0200
commitc67b505da8e678ae41bbba8ce75abb3ef0824fb8 (patch)
tree7c1ed1e975b755b8b3ec899b0826ce2ff6968cae /challenge-082/juliodcs
parentd198f9c1f1477ca6a02f67dade78b846fff54d02 (diff)
downloadperlweeklychallenge-club-c67b505da8e678ae41bbba8ce75abb3ef0824fb8.tar.gz
perlweeklychallenge-club-c67b505da8e678ae41bbba8ce75abb3ef0824fb8.tar.bz2
perlweeklychallenge-club-c67b505da8e678ae41bbba8ce75abb3ef0824fb8.zip
Optimize it a little
Diffstat (limited to 'challenge-082/juliodcs')
-rw-r--r--challenge-082/juliodcs/perl/ch-2.pl6
-rw-r--r--challenge-082/juliodcs/raku/ch-2.raku6
2 files changed, 6 insertions, 6 deletions
diff --git a/challenge-082/juliodcs/perl/ch-2.pl b/challenge-082/juliodcs/perl/ch-2.pl
index e21df5eee7..a3736cde3f 100644
--- a/challenge-082/juliodcs/perl/ch-2.pl
+++ b/challenge-082/juliodcs/perl/ch-2.pl
@@ -5,9 +5,9 @@ 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 || $a eq $b)
+ my $found = 0
+ $c =~ s/\Q$a\E|\Q$b\E/ $found++; '' /e for 1 .. 2;
+ $c eq q() && ($found == 2 || $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 ad7c3388f9..2d15b4937e 100644
--- a/challenge-082/juliodcs/raku/ch-2.raku
+++ b/challenge-082/juliodcs/raku/ch-2.raku
@@ -2,9 +2,9 @@
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))
+ my $found = 0;
+ $c ~~ s/ $a | $b /{ $found++; 「」 }/ for ^2;
+ +($c eq 「」 && ($found == 2 || $a eq $b))
}
say interleaved |@*ARGS;