Created
January 13, 2020 03:51
-
-
Save emesterhazy/f92e7e2dc1a88cbefa79651ef35b3a8d to your computer and use it in GitHub Desktop.
First few lines of 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
open Base | |
open Stdio | |
let fizzbuzz i = | |
match (i % 3, i % 5) with | |
| (0,0) -> "FizzBuzz" | |
| (0,_) -> "Fizz" | |
| (_,0) -> "Buzz" | |
| _ -> Int.to_string i | |
let rec range_apply i n ~f = | |
match i with | |
| _ when i = n + 1 -> () | |
| _ -> f i; | |
range_apply (i + 1) n ~f | |
let rec get_int () = | |
printf "Max number: "; | |
Out_channel.flush stdout; | |
let line = In_channel.input_line In_channel.stdin in | |
match line with | |
| None -> get_int () | |
| Some x -> try | |
Int.of_string x | |
with | |
| Failure _ -> get_int () | |
let () = | |
let max = get_int () in | |
range_apply 1 max ~f:(fun x -> printf "%s\n" (fizzbuzz x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment