aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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";
+ }
+}