diff options
| -rw-r--r-- | challenge-346/ash/raku/ch-1.raku | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-346/ash/raku/ch-1.raku b/challenge-346/ash/raku/ch-1.raku new file mode 100644 index 0000000000..3b1cff46f7 --- /dev/null +++ b/challenge-346/ash/raku/ch-1.raku @@ -0,0 +1,25 @@ +# Task 1 of The Weekly Challenge 346 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-346/#TASK1 + +say paren-len '(()())'; # 6 +say paren-len ')()())'; # 4 +say paren-len '((()))()(((()'; # 8 +say paren-len '))))((()('; # 2 +say paren-len '()(()'; # 2 + +# An extra example to find the longest string out of the two options +say paren-len '()((())'; # 4 + +grammar parens { + rule sequence { + <balanced>+ + } + + rule balanced { + '(' <balanced>* ')' + } +} + +sub paren-len($s) { + $s.match(/<parens::sequence>/, :g)>>.chars.max; +} |
