DEV Community

loading...

Discussion on: FizzBuzz challenge in as many languages as possible

Collapse
vrotaru profile image
Vasile Rotaru

Language: OCaml
Code:

let fizzbuzz n =
  let rec loop i max div3 div5 =
    if i < max then
      match i = div3, i = div5 with
      | true, true   -> print_endline "FizzBuzz"; loop (i + 1) max (div3 + 3) (div5 + 5)
      | true, false  -> print_endline "Fizz"; loop (i + 1) max (div3 + 3) div5
      | false, true  -> print_endline "Buzz"; loop (i + 1) max div3 (div5 + 5)
      | false, false -> print_endline (string_of_int i); loop (i + 1) max div3 div5
  in
  loop 1 n 3 5

let _ = fizzbuzz 100
Collapse
teotcd profile image
JedDevs Author

Interesting! What kind of work is OCaml used for? 😊

Thread Thread
vrotaru profile image
Vasile Rotaru

Compilers, Proof Assistants, Static Verification Tools. Facebook uses it a lot under the hood.

Thread Thread
teotcd profile image
JedDevs Author

Interesting.
Welcome to dev.to btw (saw you joined today).