aboutsummaryrefslogtreecommitdiff
path: root/challenge-209
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-04-02 23:52:12 +0100
committerGitHub <noreply@github.com>2023-04-02 23:52:12 +0100
commit87bad2a480ca75cba828cf56b7f649045b449b0f (patch)
treeaf9ce8905d92920b7c17e31b000440c8abced371 /challenge-209
parent8915a66de2cb2a724aee5e55ddfc15580cfdf1d5 (diff)
parent95c661a12b81513cdddc3977c02262668a58a68c (diff)
downloadperlweeklychallenge-club-87bad2a480ca75cba828cf56b7f649045b449b0f.tar.gz
perlweeklychallenge-club-87bad2a480ca75cba828cf56b7f649045b449b0f.tar.bz2
perlweeklychallenge-club-87bad2a480ca75cba828cf56b7f649045b449b0f.zip
Merge pull request #7818 from simon-dueck/master
Added solutions for weeks 209 and 210
Diffstat (limited to 'challenge-209')
-rw-r--r--challenge-209/simon-dueck/fsharp/ch-1.fsx18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-209/simon-dueck/fsharp/ch-1.fsx b/challenge-209/simon-dueck/fsharp/ch-1.fsx
new file mode 100644
index 0000000000..d376088f2f
--- /dev/null
+++ b/challenge-209/simon-dueck/fsharp/ch-1.fsx
@@ -0,0 +1,18 @@
+(*
+ 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"
+ Write a script to print 1 if the last character is an “a” otherwise print 0.
+*)
+
+let rec decode (arr): int =
+ match arr with
+ | [x] when not x -> 1 // last character decodes to 'a'
+ | x::y::xs when x -> decode xs // list begins with 'b' or 'c'
+ | x::xs when not x -> decode xs // list begins with 'a'
+ | _ -> 0
+
+printfn $"{decode [true; true; false; false; true; false; false;]}"
+printfn $"{decode [true; true; false; false; true; false;]}" \ No newline at end of file