Language Scala
(GrabbaBeer & CaseOfBeers)
Date: | 05/30/09 |
Author: | D Mackenzie |
URL: | n/a |
Comments: | 0 |
Info: | http://www.scala-lang.org |
Score: | (2.91 in 11 votes) |
import io.Source // Lazy, brittle "rob the store" version object GrabbaBeer extends Application { val buf = new StringBuilder; for (c <- Source.fromURL("http://99-bottles-of-beer.net/lyrics.html")) buf.append(c) val Pat = "<p>(.*?)<br/?>\\s*(.*?)</p>".r for (Pat(l1, l2) <- Pat findAllIn buf) println(l1 + "\n" + l2 + "\n") } // Law-abiding concise version. object CaseOfBeers extends Application { def qty(n: Int) = (n match {case 0 => "no more bottles" case 1 => "1 bottle" case n => n + " bottles"}) + " of beer" for (b <- 99 to 0 by -1) println(qty(b).capitalize + " on the wall, " + qty(b) + "." + (if (b > 0) "\nTake one down and pass it around, " + qty(b - 1) + " on the wall.\n" else "\nGo to the store and buy more beer, " + qty(99) + " on the wall.")) } // Cheers!
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
Scala with a vengeance | Eduardo Costa | 09/16/09 | 0 | |
Fun semi-DSL readable version | Calum Leslie | 01/31/08 | 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