my @digits = <ook ookook oog ooga ug mook mookmook oogam oogum ugug>;
sub sequence-count(Str:D $n --> UInt:D) {
return 1 unless $n;
[+] @digits.map({ sequence-count($n.substr($_.chars)) if $n.starts-with($_) });
}
use Test;
is sequence-count('ookookook'), 3, 'ookookook => 3';
is sequence-count('oogamookoogumook'), 2, 'oogamookoogumook => 2';
is sequence-count('oogoogumookookmookmookookookmookook'), 8, 'oogoogumookookmookmookookookmookook => 8';
is sequence-count('mookookookugoogumoogummookmookugmookookmookmook'), 8, 'mookookookugoogumoogummookmookugmookookmookmook => 8';
is sequence-count('mookmookoogamoogumookookugoogugoogammookmookookookoogoogumugugookmookoogugug'), 64, 'mookmookoogamoogumookookugoogugoogammookmookookookoogoogumugugookmookoogugug => 64';
is sequence-count('ookugugugugoogookookugugugugmookmookugugugugugookookmookmookmookmookoogmookmookoogaooga'), 16000, 'ookugugugugoogookookugugugugmookmookugugugugugookookmookmookmookmookoogmookmookoogaooga => 16000';
done-testing;