aboutsummaryrefslogtreecommitdiff
path: root/challenge-209
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2023-03-27 01:18:11 +0200
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2023-03-27 01:18:11 +0200
commitc5fb8164dcc10f8cb67002d9d5a419e42dc00485 (patch)
tree85db6503c3a2cec448dfe4eb09ecfbd6363f175e /challenge-209
parente26e6c2116af0c7e813a715ac5d0cf5a1c712578 (diff)
downloadperlweeklychallenge-club-c5fb8164dcc10f8cb67002d9d5a419e42dc00485.tar.gz
perlweeklychallenge-club-c5fb8164dcc10f8cb67002d9d5a419e42dc00485.tar.bz2
perlweeklychallenge-club-c5fb8164dcc10f8cb67002d9d5a419e42dc00485.zip
feat: add solution for challenge 209-1 from BarrOff
Diffstat (limited to 'challenge-209')
-rw-r--r--challenge-209/barroff/raku/ch-1.raku33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-209/barroff/raku/ch-1.raku b/challenge-209/barroff/raku/ch-1.raku
new file mode 100644
index 0000000000..ea7857dc7c
--- /dev/null
+++ b/challenge-209/barroff/raku/ch-1.raku
@@ -0,0 +1,33 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+grammar Sbc {
+ regex TOP { <prelude> <end> }
+ token a { '0' }
+ token b { '10' }
+ token c { '11' }
+ regex prelude { ^ [ <a> | <b> | <c> ]* }
+ token end { <a> $ }
+}
+
+sub special-bit-characters(Int @numbers --> Int) {
+ my Str $bit-string = @numbers.join;
+ Sbc.parse($bit-string) ?? 1 !! 0;
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 2;
+
+ is special-bit-characters(Array[Int].new([1, 0, 0])), 1, "works for (1, 0, 0)";
+ is special-bit-characters(Array[Int].new([1, 1, 1, 0])), 0, "works for (1, 1, 1, 0)";
+}
+
+#| Take user provided list like 1 1 1 0
+multi sub MAIN(*@elements where @elements.elems ≥ 1 && all(@elements) ~~ /^<[01]>$/) {
+ my Int @int-elements = @elements;
+ say "the result is { special-bit-characters(@int-elements) }"
+}
+