aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Shitov <ash@Andreys-iMac.local>2025-11-05 23:24:04 +0200
committerAndrey Shitov <ash@Andreys-iMac.local>2025-11-05 23:24:04 +0200
commit95d316f3e15e1e3e14db8ceb31115ae8df2a4067 (patch)
tree0f9cf9deab66f6e217d6b85bb54cc0bca7fb38ba
parent2d5efa505de21f262b29e35e02296e1fe52a11da (diff)
downloadperlweeklychallenge-club-95d316f3e15e1e3e14db8ceb31115ae8df2a4067.tar.gz
perlweeklychallenge-club-95d316f3e15e1e3e14db8ceb31115ae8df2a4067.tar.bz2
perlweeklychallenge-club-95d316f3e15e1e3e14db8ceb31115ae8df2a4067.zip
Task 1 Week 346 in Raku by @ash
-rw-r--r--challenge-346/ash/raku/ch-1.raku25
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;
+}