Language F#
(Recursive implementation)
Date: | 07/04/09 |
Author: | Alec Zorab |
URL: | n/a |
Comments: | 0 |
Info: | http://research.microsoft.com/fsharp |
Score: | (2.81 in 16 votes) |
//Note that to conform the 100 characters per line rule, two calls to printfn are used //in each case. As a result, this is slightly more verbose than necessary, but is pretty let rec bottlesOfBeer = function 0 -> printfn "No more bottles of beer on the wall, no more bottles of beer." printfn "Go to the store and buy some more, 99 bottles of beer on the wall.\n" | 1 -> printfn "1 bottle of beer on the wall, 1 bottle of beer." printfn "Take it down and pass it around, no more bottles of beer on the wall.\n" bottlesOfBeer 0 | 2 -> printfn "2 bottles of beer on the wall, 2 bottles of beer." printfn "Take one down, pass it around, 1 bottle of beer on the wall.\n" bottlesOfBeer 1 | n -> printfn "%d bottles of beer on the wall, %d bottles of beer." n n printfn "Take one down, pass it around, %d bottles of beer on the wall.\n" (n-1) bottlesOfBeer (n - 1) bottlesOfBeer 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 | |
Tail Recursion Call | Simon Kang | 06/22/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