Language F#
(Tail Recursion Call)
| Date: | 06/22/09 |
| Author: | Simon Kang |
| URL: | n/a |
| Comments: | 0 |
| Info: | n/a |
| Score: |
let rec writeBeerSong n =
let bottleString1 n1 =
match n1 with
| 0 -> "no more bottles of beer"
| 1 -> "1 bottle of beer"
| _ -> n1.ToString() + " bottles of beer"
let bottleString2 n2 =
match n2 with
| 0 -> "No more bottles of beer on the wall"
| _ -> bottleString1 n2 + " on the wall"
printfn "%s, %s" (bottleString2 n) (bottleString1 n)
match n with
| 0 -> printf "Go to the store and buy some more,"
printfn " 99 bottles of beer on the wall."
| _ -> printfn "Take one down and pass it around, %s on the wall.\n"
(bottleString1 (n - 1))
writeBeerSong (n - 1)
writeBeerSong 99
Download Source | Write Comment
Alternative Versions
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| Using list comprehension | Jörn Rönnow | 02/01/09 | 3 | |
| Cleaner still | Don Syme | 12/07/06 | 0 | |
| Recursive implementation | Alec Zorab | 07/04/09 | 0 | |
| lists and lambda's | Kyle Eppley | 05/04/10 | 0 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments