Created
September 27, 2015 16:05
-
-
Save Nnwww/4c4dc58683b46d563191 to your computer and use it in GitHub Desktop.
FizzBuzz in OCaml
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
open List;; | |
let fizzbuzz min max = | |
let say cur = | |
match (cur mod 3, cur mod 5) with | |
| (0, 0) -> "FizzBuzz" | |
| (0, _) -> "Fizz" | |
| (_, 0) -> "Buzz" | |
| (_, _) -> string_of_int cur | |
in | |
let rec loop strs cur = | |
if cur < min then | |
strs | |
else | |
loop (say cur :: strs) (cur - 1) | |
in | |
let res = loop [] max in | |
map res (Printf.sprintf "%s");; |
Author
Nnwww
commented
Sep 27, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment