diff options
| author | simon-dueck <126712673+simon-dueck@users.noreply.github.com> | 2023-03-28 14:10:29 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-28 14:10:29 -0500 |
| commit | 2b1861cb0e15fc0dba9900b294cd018effbf7d3f (patch) | |
| tree | b07049e89dbd8a390a7dfb32c34e86b58bf674b3 /challenge-209 | |
| parent | 8915a66de2cb2a724aee5e55ddfc15580cfdf1d5 (diff) | |
| download | perlweeklychallenge-club-2b1861cb0e15fc0dba9900b294cd018effbf7d3f.tar.gz perlweeklychallenge-club-2b1861cb0e15fc0dba9900b294cd018effbf7d3f.tar.bz2 perlweeklychallenge-club-2b1861cb0e15fc0dba9900b294cd018effbf7d3f.zip | |
Added solution for challenge 1
Diffstat (limited to 'challenge-209')
| -rw-r--r-- | challenge-209/simon-dueck/fsharp/ch-1.fsx | 18 |
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 |
