Created
July 18, 2018 12:29
-
-
Save fujimaki-k/b062db5b59ca453acb1f601742bd1292 to your computer and use it in GitHub Desktop.
fizzbuzz.js の答え合わせ用に、OCaml で再帰を使って FizzBuzz を実装してみました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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