FunctionsFTW/99 bottles of beer

From Esolang
Jump to navigation Jump to search
setNum("bottles", 99);                                   "Set X (bottles) to 99";
setStr("form", " bottles");                              "Plural";

label("l");
if(gt(getNum("bottles"), 0), () {                        "If X > 0";
  print(numToStr(getNum("bottles")));                      "X bottle(s) of beer on the wall,";
  print(getStr("form"));
  print(" of beer on the wall,\n");

  print(numToStr(getNum("bottles")));                      "X bottle(s) of beer.";
  print(getStr("form"));                                   "Take one down, pass it around,";
  print(" of beer.\nTake one down, pass it around,\n");

  setNum("bottles", add(getNum("bottles"), neg(1)));       "X--";
  if(eqNum(getNum("bottles"), 1), () {                     "If X = 1";
    setStr("form", " bottle");                               "Singular";
  }, () {                                                  "Else";
    setStr("form", " bottles");                              "Plural";
  });

  if(gt(getNum("bottles"), 0), () {                        "If X > 0";
    print(numToStr(getNum("bottles")));                      "Use X";
  }, () {                                                  "Else";
    print("No");                                             "Use No";
  });
  print(getStr("form"));                                   "X/No bottle(s) of beer on the wall.";
  print(" of beer on the wall.\n\n");
  goto("l");                                               "Repeat";
}, () {});

Minimized (522 bytes)

setNum("b",99);setStr("f"," bottles");label("l");if(gt(getNum("b"),0),(){print(numToStr(getNum("b")));print(getStr("f"));print(" of beer on the wall,\n");print(numToStr(getNum("b")));print(getStr("f"));print(" of beer.\nTake one down, pass it around,\n");setNum("bottles",add(getNum("b"),neg(1)));if(eqNum(getNum("b"),1),(){setStr("f"," bottle");},(){setStr("f"," bottles");});if(gt(getNum("b"),0),(){print(numToStr(getNum("b")));},(){print("No");});print(getStr("f"));print(" of beer on the wall.\n\n");goto("l");},(){});