Last active
March 21, 2017 01:47
-
-
Save dakatsuka/e71c699c227f717e3b27 to your computer and use it in GitHub Desktop.
FizzBuzz with OCaml
This file contains hidden or 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 rec range a b accum = | |
if a > b then accum | |
else range a (b - 1) (b :: accum) | |
let fizzbuzz xs = | |
let f = function | |
| n when n mod 15 = 0 -> "FizzBuzz" | |
| n when n mod 3 = 0 -> "Fizz" | |
| n when n mod 5 = 0 -> "Buzz" | |
| n -> string_of_int n | |
in xs |> List.map f | |
let _ = | |
range 1 100 [] |> fizzbuzz |> List.iter (Printf.printf "%s\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment