diff options
| author | juliodcs <julio.dcs@gmail.com> | 2020-10-16 20:35:37 +0200 |
|---|---|---|
| committer | juliodcs <julio.dcs@gmail.com> | 2020-10-16 20:35:37 +0200 |
| commit | d04340bbc0ff6dc42a4fe2fc6cc849ff4bc53c66 (patch) | |
| tree | 0cd1212bf19dbda3547b60c5ccfad1a139d56678 /challenge-082/juliodcs | |
| parent | 6a7091fc5d3377840b1b80a755e5f5e0b0283cab (diff) | |
| download | perlweeklychallenge-club-d04340bbc0ff6dc42a4fe2fc6cc849ff4bc53c66.tar.gz perlweeklychallenge-club-d04340bbc0ff6dc42a4fe2fc6cc849ff4bc53c66.tar.bz2 perlweeklychallenge-club-d04340bbc0ff6dc42a4fe2fc6cc849ff4bc53c66.zip | |
Re-do ch-2; I completely misunderstood the requirements 😳
Diffstat (limited to 'challenge-082/juliodcs')
| -rw-r--r-- | challenge-082/juliodcs/perl/ch-2.pl | 9 | ||||
| -rw-r--r-- | 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;
|
