Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

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

VersionAuthorDateCommentsRate
Using list comprehensionJörn Rönnow02/01/093
Cleaner stillDon Syme12/07/060
Tail Recursion CallSimon Kang06/22/090
lists and lambda'sKyle Eppley05/04/100

Comments

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!

Name:

eMail:

URL:

Security Code:
  
Comment: