diff options
| author | Simon Proctor <simon.proctor@gmail.com> | 2021-02-08 12:44:36 +0000 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@gmail.com> | 2021-02-08 12:44:36 +0000 |
| commit | 4fab0d2297a2e9dc0872f537f0e084550bd1a03b (patch) | |
| tree | cfbadc591fddd5d1ca8eeb695afc9e0dd764edc4 | |
| parent | 386d1f3ed654a7928cd7173bcf07e5e392a9fbcf (diff) | |
| download | perlweeklychallenge-club-4fab0d2297a2e9dc0872f537f0e084550bd1a03b.tar.gz perlweeklychallenge-club-4fab0d2297a2e9dc0872f537f0e084550bd1a03b.tar.bz2 perlweeklychallenge-club-4fab0d2297a2e9dc0872f537f0e084550bd1a03b.zip | |
Challenge 2
| -rw-r--r-- | challenge-099/simon-proctor/raku/ch-2.raku | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-099/simon-proctor/raku/ch-2.raku b/challenge-099/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..1f3d1da12d --- /dev/null +++ b/challenge-099/simon-proctor/raku/ch-2.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + +use v6; + +#| Given two strings see how often you can find sequences of the second string in the first. +sub MAIN( Str $S, Str $T ) { + say sub-count($S.comb, $T.comb); +} + +multi sub sub-count( @ where *.elems == 0, @ where *.elems > 0 ) { 0 } +multi sub sub-count( @, @ where *.elems == 0 ) { 1 } + +multi sub sub-count( @S, @T where @S[0] ~~ @T[0] ) { + return sub-count( @S[1..*], @T[1..*] ) + + sub-count( @S[1..*], @T ); +} + +multi sub sub-count( @S, @T ) { + return sub-count( @S[1..*], @T ); +} |
