Skip to content

Instantly share code, notes, and snippets.

@nobleach nobleach/beerSong.ml
Created Feb 12, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.