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 Haskell

(Using list comprehension)

Date:11/21/08
Author:Ben Firner
URL:n/a
Comments:0
Info:http://www.haskell.org
Score: (2.75 in 16 votes)
--99 bottles of beer on the wall song
--x holds the remaining number of bottles.
--The strings in b1 and b2 are based upon the current value of x.
--b3 capitalizes b1
--line2 depends on x and is built from b2 except in the last verse
main = (putStr (unlines
        [b3++" of beer on the wall, "++b1++" of beer.\n"++line2++" of beer on the wall.\n" |
         x<-[99,98..0],
         b1<-["no more bottles",show x++" bottles",show x++" bottle"],
         b2<-["no more bottles",show (x-1)++" bottles", show (x-1)++" bottle"],
         b3<-[b1, "N"++tail b1],
         line2<-["Take one down and pass it around, "++b2,
                 "Go to the store and buy some more, 99 bottles"],
         ((b1 == show x++" bottle") == (x == 1)), ((b1 == "no more bottles") == (x == 0)),
         ((last b2 == 'e') == (x == 2)), (head b2 == 'n') == (x == 1),
         ((b3 == "N"++tail b1) == (head b1 == 'n')),
         ((head line2 == 'G') == (x == 0))]))

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
1Iavor03/03/065
Using guardsSimon Johansson10/25/073
With monads and monad transformerAdrien Piérard12/25/062

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: