FunctionsFTW/Factorial

From Esolang
Jump to navigation Jump to search
setNum("input", strtoNum(input()));                           "Get number";
setNum("result", 1);                                          "The result";

label("l");
if(gt(getNum("input"), 1), () {                               "If input > 1";
  setNum("result", mult(getNum("result"), getNum("input")));    "result = result * input";
  setNum("input", add(getNum("input"), neg(1)));                "input--";
  goto("l");                                                    "Repeat";
}, () {});

print(numToStr(getNumber("result")));                         "Print result";

Minimized (207 bytes)

setNum("i",strtoNum(input()));setNum("r",1);label("l");if(gt(getNum("i"),1),(){setNum("r",mult(getNum("r"),getNum("i")));setNum("i",add(getNum("i"),neg(1)));goto("l");},(){});print(numToStr(getNumber("r")));