Created
February 12, 2018 02:11
-
-
Save nobleach/8855379bd353b6287f57700af498f184 to your computer and use it in GitHub Desktop.
Bottles of Beer
This file contains 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 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