aboutsummaryrefslogtreecommitdiff
path: root/challenge-042
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2021-01-06 15:16:42 +0800
committer冯昶 <seaker@qq.com>2021-01-06 15:16:42 +0800
commit8d8f3d2effddf8b25dab04cb31f39973a34c57e4 (patch)
tree2052492a4af5461368c833f6a929559c8ca5e792 /challenge-042
parentc30a4f384556c417f84915d02d98552d317b01dc (diff)
downloadperlweeklychallenge-club-8d8f3d2effddf8b25dab04cb31f39973a34c57e4.tar.gz
perlweeklychallenge-club-8d8f3d2effddf8b25dab04cb31f39973a34c57e4.tar.bz2
perlweeklychallenge-club-8d8f3d2effddf8b25dab04cb31f39973a34c57e4.zip
challenge #042, raku solutions
Diffstat (limited to 'challenge-042')
-rwxr-xr-xchallenge-042/feng-chang/ch-1.raku2
-rwxr-xr-xchallenge-042/feng-chang/ch-2.raku28
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-042/feng-chang/ch-1.raku b/challenge-042/feng-chang/ch-1.raku
new file mode 100755
index 0000000000..83b4c4a5f6
--- /dev/null
+++ b/challenge-042/feng-chang/ch-1.raku
@@ -0,0 +1,2 @@
+#!/bin/env raku
+(^51).map({ put "Decimal $_ = Octal { .base(8) }" });
diff --git a/challenge-042/feng-chang/ch-2.raku b/challenge-042/feng-chang/ch-2.raku
new file mode 100755
index 0000000000..c5f7106d4a
--- /dev/null
+++ b/challenge-042/feng-chang/ch-2.raku
@@ -0,0 +1,28 @@
+#!/bin/env raku
+
+sub is-balanced(Str:D $s --> Bool) {
+ my Int $i;
+ for $s.comb {
+ when '(' { ++$i }
+ when ')' { --$i; return False if $i < 0; }
+ default { return False }
+ }
+
+ $i == 0;
+}
+
+multi MAIN('test') {
+ use Test;
+
+ ok is-balanced('()'), '() is good';
+ ok is-balanced('(())'), '(()) is good';
+
+ nok is-balanced(')('), ')( is bad';
+ nok is-balanced('())()'), '())() is bad';
+}
+
+multi MAIN(Str:D $string-of-braces) {
+ given $string-of-braces {
+ put "$_ -{ ' not' if !is-balanced($_) } ok";
+ }
+}