From 4fab0d2297a2e9dc0872f537f0e084550bd1a03b Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 8 Feb 2021 12:44:36 +0000 Subject: Challenge 2 --- challenge-099/simon-proctor/raku/ch-2.raku | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 challenge-099/simon-proctor/raku/ch-2.raku 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 ); +} -- cgit