From d04340bbc0ff6dc42a4fe2fc6cc849ff4bc53c66 Mon Sep 17 00:00:00 2001 From: juliodcs Date: Fri, 16 Oct 2020 20:35:37 +0200 Subject: Re-do ch-2; I completely misunderstood the requirements 😳 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- challenge-082/juliodcs/perl/ch-2.pl | 9 +++++---- challenge-082/juliodcs/raku/ch-2.raku | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/challenge-082/juliodcs/perl/ch-2.pl b/challenge-082/juliodcs/perl/ch-2.pl index 6480571850..5e6398cfdf 100644 --- a/challenge-082/juliodcs/perl/ch-2.pl +++ b/challenge-082/juliodcs/perl/ch-2.pl @@ -2,10 +2,11 @@ use strict; use warnings; use experimental 'signatures'; use feature 'say'; -use experimental 'smartmatch'; -sub comparable($string) { - join q(), sort split m//, $string +sub interleaved($a, $b, $c) { + 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 } -say comparable(shift . shift) eq comparable(shift) ? 1 : 0; +say interleaved(@ARGV) ? 1 : 0; diff --git a/challenge-082/juliodcs/raku/ch-2.raku b/challenge-082/juliodcs/raku/ch-2.raku index 2b4cfcc3ee..2821998f72 100644 --- a/challenge-082/juliodcs/raku/ch-2.raku +++ b/challenge-082/juliodcs/raku/ch-2.raku @@ -1,9 +1,9 @@ #!/usr/bin/env raku -sub infix:<≈≈>(Str \x, Str \y) is equiv(&[eq]) returns Bool { - x.ords.sort == y.ords.sort +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 MAIN(Str \a, Str \b, Str \c) { - say +(a ~ b ≈≈ c) -} +say interleaved |@*ARGS; -- cgit