I just found out about the Fizz Buzz Test yesterday, and I was so excited about solving it with the minimal OCaml knowledge I have! So I did it! You can find it on my github.
While writing this program, I learned that semicolons are helpful markers! You are to separate each expressions with a single semicolon. You are to separate each definition or function call with two semicolon. E.g.,
let fizzbuzztest x = if x mod 3 = 0 then if x mod 5 = 0 then print_string ("fizzbuzz")let fizzbuzztest x = if x mod 3 = 0 then if x mod 5 = 0 then print_string ("fizzbuzz") else print_string ("fizz") else if x mod 5 = 0 then print_string ("buzz") else print_int x ; (*end of if statement*) print_newline () ;; (*end of definition of fizzbuzztest *)
let rec counter_fizzbuzz n = match n with 0 -> () | _ -> counter_fizzbuzz (n - 1) ; (*end of first expression in match with _ *) fizzbuzztest n ;; (*end of definition of counter_fizzbuzz *) counter_fizzbuzz 100 ;;
Apparently a large percentage of job candidates cannot pass the test. I feel so encouraged that I can do this!