Skip to content

Instantly share code, notes, and snippets.

@fujimaki-k
Created July 18, 2018 12:29
Show Gist options
  • Save fujimaki-k/b062db5b59ca453acb1f601742bd1292 to your computer and use it in GitHub Desktop.
Save fujimaki-k/b062db5b59ca453acb1f601742bd1292 to your computer and use it in GitHub Desktop.
fizzbuzz.js の答え合わせ用に、OCaml で再帰を使って FizzBuzz を実装してみました。
let fizzbuzz first last =
let rec print current =
if current <= last then
match current with
| _ when current mod 15 = 0 ->
print_endline "FizzBuzz";
print (current + 1)
| _ when current mod 5 = 0 ->
print_endline "Buzz";
print (current + 1)
| _ when current mod 3 = 0 ->
print_endline "Fizz";
print (current + 1)
| _ ->
print_endline (string_of_int current);
print (current + 1)
in
print first
;;
fizzbuzz 1 100;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment