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 Mathematica

Date:02/27/06
Author:Konstantin Kouptsov
URL:n/a
Comments:0
Info:http://www.wolfram.com
Score: (2.58 in 12 votes)
(* Mathematica code *)
(* by Konstantin Kouptsov *)

With[{
  m = "no more",
  b = " bottle",
  e = " of beer",
  w = " on the wall",
  n = "\n",
  d = "Take one down and pass it around, ",
  g = "Go to the store and buy some more, "
  },
 NoMore[x_, y_] := If[x > 0, ToString[x], y];
 Plural[x_] := If[x == 1, "", "s"];
 StringJoin[MapThread[
   Function[{p, q, r},
    StringJoin[{
      NoMore[p, "No more"], b, Plural[p], e, w, ", ",
      NoMore[q, m], b, Plural[q], e, ". ", n, If[q > 0, d, g],
      NoMore[r, m], b, Plural[r], e, w, ".", If[p > 0, n <> n, ""]}]],
   {#, #, RotateLeft[#]} &[Range[99, 0, -1]]]]]

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Very short version.Brenton Bostick03/16/061
Easily extensible, English-speakingSzabolcs Horvát03/04/080
3Anonymous04/20/050

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: