aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-03-26 13:00:13 +0100
committerGitHub <noreply@github.com>2023-03-26 13:00:13 +0100
commite2fba08bcdd0cc708dfbb89c10769c1a4e06abd3 (patch)
treee97b34826cc2e1c0408be2c7ec55587714a87a62
parent72ddc74318fe458e9a99b94702b3c3933674b3b2 (diff)
parent0eb4e17ee09eeae2f6a7ca5694fbcb45ccef660f (diff)
downloadperlweeklychallenge-club-e2fba08bcdd0cc708dfbb89c10769c1a4e06abd3.tar.gz
perlweeklychallenge-club-e2fba08bcdd0cc708dfbb89c10769c1a4e06abd3.tar.bz2
perlweeklychallenge-club-e2fba08bcdd0cc708dfbb89c10769c1a4e06abd3.zip
Merge pull request #7797 from Solathian/branch-for-challenge-209
Added file challenge 209
-rw-r--r--challenge-209/solathian/perl/ch-1.pl43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-209/solathian/perl/ch-1.pl b/challenge-209/solathian/perl/ch-1.pl
new file mode 100644
index 0000000000..8a7e61d6fe
--- /dev/null
+++ b/challenge-209/solathian/perl/ch-1.pl
@@ -0,0 +1,43 @@
+#!usr/bin/perl
+use v5.36;
+
+# Challenge 209 - 1 - Special Bit Characters
+# You are given an array of binary bits that ends with 0.
+
+# Valid sequences in the bit string are:
+
+# [0] -decodes-to-> "a"
+# [1, 0] -> "b"
+# [1, 1] -> "c"
+
+
+# bits(); # error: array is empty
+# bits(1); # error: array is not ending with 0
+
+bits(0, 0, 0); # 1
+bits(1, 0, 0); # 1
+bits(1, 1, 1, 0); # 0
+bits(0, 1, 1, 1, 0); # 0
+bits(0, 1, 0, 1, 1, 0); # 1
+bits(0, 1, 0, 1, 1, 0, 0); # 1
+bits(1, 0, 1, 1, 0, 0); # 1
+bits(1, 0, 0, 1, 1, 0); # 1
+
+
+sub bits(@array)
+{
+
+ die"Array is empty" if(@array == 0);
+ die"Array is not ending with 0" if( $array[-1] != 0);
+
+
+ while(@array > 1)
+ {
+ # shift once if the first character is 0, shift twice if it is a two bit character
+ shift @array if( $array[0] == 1 );
+ shift @array;
+ }
+
+ say "0" if(@array == 0);
+ say "1" if(@array == 1);
+} \ No newline at end of file