aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krňávek <Jan.Krnavek@gmail.com>2020-10-18 13:11:43 +0200
committerJan Krňávek <Jan.Krnavek@gmail.com>2020-10-18 13:11:43 +0200
commitc2d5208ded891b4b9a21753021d96bdde0f90e6b (patch)
tree42bbc4d6823a637566e4ab72cc07012c51fa9dda
parentab2f49c69379e0ea79872935eca4c06104222c14 (diff)
downloadperlweeklychallenge-club-c2d5208ded891b4b9a21753021d96bdde0f90e6b.tar.gz
perlweeklychallenge-club-c2d5208ded891b4b9a21753021d96bdde0f90e6b.tar.bz2
perlweeklychallenge-club-c2d5208ded891b4b9a21753021d96bdde0f90e6b.zip
solutions week 082
-rw-r--r--challenge-082/wambash/raku/ch-2.raku42
1 files changed, 34 insertions, 8 deletions
diff --git a/challenge-082/wambash/raku/ch-2.raku b/challenge-082/wambash/raku/ch-2.raku
index 6b159c8eaf..b15a83588a 100644
--- a/challenge-082/wambash/raku/ch-2.raku
+++ b/challenge-082/wambash/raku/ch-2.raku
@@ -1,18 +1,44 @@
#!/usr/bin/env raku
-multi iter ( ( (),Empty ) ) {
+multi step ( ( :@what where :!elems, :@from where :!elems ) ) {
True
}
-multi iter ( (@c,+@a) ) {
- @a.first: { .head eqv @c.head}, :k
- andthen \(@c.skip, |@a[0..^ $_], @a[$_].skip.cache||Empty, |@a[$_ ^.. *])
+multi step ( (:@what, :@from ) ) {
+ @from.first: { .head eqv @what.head}, :k
+ andthen \(
+ what => @what.skip,
+ from => (
+ |@from[0 ..^ $_],
+ @from[$_].skip.cache || Empty,
+ |@from[$_ ^.. *]
+ ).pick(*),
+ )
orelse False
}
-\((1,2,2,2,3),(1,2),(2,2,3)), *.&iter ... Bool
-andthen .say;
+multi interleave ( :@what, :@from ) {
+ \( :@what, :@from )
+ andthen $_, *.&step ... Bool
+}
+
+multi interleave ( Str :$what, :@from ) {
+ samewith(
+ what => $what.comb,
+ from => @from.map: *.comb.cache,
+ ).tail
+}
+
+
+multi MAIN ( $what, +@from ) {
+ say interleave(:$what, :@from)
+}
-sub interleave-string (@c, +@a) {
- ...
+multi MAIN (Bool :$test!) {
+ use Test;
+ is-deeply interleave( :what(1,2,2,3), :from((1,2),(2,3)) ).[*-3], \( :what((3).Seq),:from(((3,),).Seq) );
+ ok interleave( :what<XXY>, :from<XY X> );
+ ok interleave( :what<XXXXZY>, :from<XXY XXZ> );
+ nok interleave( :what<XXY>, :from<YX X> );
+ done-testing;
}