Language Scala
(Fun semi-DSL readable version)
Date: | 01/31/08 |
Author: | Calum Leslie |
URL: | http://www.zootm.co.uk |
Comments: | 0 |
Info: | http://www.scala-lang.org |
Score: | (2.96 in 28 votes) |
object NinetyNineBottles { def main(args: Array[String]) = { for (verse <- (1 to 99).reverse.map(verse _)) { println(verse) println } println(line1(0)) println("Go to the store and buy some more, " + (99 bottles) + " of beer on the wall.") } def verse(n: Int) = line1(n) + '\n' + line2(n) def line1(n: Int) = (n bottles).capitalize + " of beer on the wall, " + (n bottles) + " of beer." def line2(n: Int) = "Take one down, pass it around, " + ((n-1) bottles) + " of beer on the wall." implicit def intToBottlesInt(i: Int) = new BottlesInt(i) } class BottlesInt(i: Int) { def bottles = i match { case 0 => "no more bottles" case 1 => "1 bottle" case n => n + " bottles" } }
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
Scala with a vengeance | Eduardo Costa | 09/16/09 | 0 | |
GrabbaBeer & CaseOfBeers | D Mackenzie | 05/30/09 | 0 | |
Animated version | D Mackenzie | 10/02/09 | 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