Language Haskell
(Using list comprehension)
| Date: | 11/21/08 |
| Author: | Ben Firner |
| URL: | n/a |
| Comments: | 0 |
| Info: | http://www.haskell.org |
| Score: |
--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
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| Using guards | Simon Johansson | 10/25/07 | 3 | |
| 2 | Iavor | 03/03/06 | 4 | |
| With monads and monad transformer | Adrien Piérard | 12/25/06 | 2 |
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