Skip to content

Instantly share code, notes, and snippets.

@nobleach
Created February 12, 2018 02:11
Show Gist options
  • Save nobleach/8855379bd353b6287f57700af498f184 to your computer and use it in GitHub Desktop.
Save nobleach/8855379bd353b6287f57700af498f184 to your computer and use it in GitHub Desktop.
Bottles of Beer
let bottles = function
| 0 -> "no more bottles"
| 1 -> "1 bottle"
| n -> Printf.sprintf "%d bottles" n;;
let rec sing n =
let current = bottles n in
let next = bottles (n-1) in
Printf.printf
"%s of beer on the wall, %s of beer.\n"
(String.capitalize_ascii current) current ;
if n > 0 then begin
Printf.printf
"Take one down and pass it around, %s of beer on the wall.\n\n"
next ;
sing (n-1)
end else
Printf.printf
"Go to the store and buy some more, 99 bottles of beer on the wall.\n"
let run = sing 99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment