Skip to content

Instantly share code, notes, and snippets.

@emesterhazy
Created January 13, 2020 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emesterhazy/f92e7e2dc1a88cbefa79651ef35b3a8d to your computer and use it in GitHub Desktop.
Save emesterhazy/f92e7e2dc1a88cbefa79651ef35b3a8d to your computer and use it in GitHub Desktop.
First few lines of Ocaml...
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