From 2b1861cb0e15fc0dba9900b294cd018effbf7d3f Mon Sep 17 00:00:00 2001 From: simon-dueck <126712673+simon-dueck@users.noreply.github.com> Date: Tue, 28 Mar 2023 14:10:29 -0500 Subject: Added solution for challenge 1 --- challenge-209/simon-dueck/fsharp/ch-1.fsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 challenge-209/simon-dueck/fsharp/ch-1.fsx 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 -- cgit