[Question]
  [
## Task
Given a non-negative integer \$n\$, evaluate the factorial \$n!\$.
The factorial is defined as follows:
$$
n!=\begin{cases}1 & n=0\\n\times(n-1)!&n>0\end{cases}
$$
## Rules
* All default I/O methods are allowed.
* Standard loopholes are forbidden.
* Built-ins are allowed.
* There is no time or memory limit.
* Giving imprecise or incorrect results for large inputs due to the limit of the native number format is fine, as long as the underlying algorithm is correct. Specifically, [it is not allowed to abuse the native number type to trivialize the challenge](https://codegolf.meta.stackexchange.com/a/8245/76162), which is one of the standard loopholes.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest code in bytes wins, but feel free to participate in various esolangs (especially the ones hindered by the restrictions of the former challenge).
## Test cases
```
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
11! = 39916800
12! = 479001600
```
---
**Note:** We already have the [old factorial challenge](https://codegolf.stackexchange.com/q/607/78410), but it has some restrictions on the domain, performance, and banning built-ins. As [the consensus here](https://codegolf.meta.stackexchange.com/a/19220/78410) was to create a separate challenge without those restrictions so that more esolangs can participate, here it goes.
Also, we discussed [whether we should close the old one as a duplicate of this](https://codegolf.meta.stackexchange.com/q/19247/78410), and we decided to [leave it open](https://codegolf.meta.stackexchange.com/a/19248/78410).
  
[Answer]
# [Shakespeare Programming Language](https://github.com/TryItOnline/spl), 106 bytes
```
,!Ajax,!Puck,!Act I:!Scene I:![Enter Ajax and Puck]Ajax:Listen tothy!You is the factorial ofyou!Open heart
```
[Try it online!](https://tio.run/##FcoxC4MwEIbhv/Ld7lJHtw4dCoKFTqU4HOlJYiUnyQXqr0/N9r7w5H2rtaPryr@OHsV9z3aG@0BPJ1FavG/RJKERcPygqbndMIZsEmFq/qCXFoQM84KFnWkKvEGXQwtN@6m8cLJaL/0f "Shakespeare Programming Language – Try It Online")
Uses the built-in `the factorial of`, which isn't described at all in the [official docs](http://shakespearelang.sourceforge.net/report/shakespeare/).
### Commented
```
,!Ajax,!Puck,!Act I:!Scene I:![Enter Ajax and Puck] # header
Ajax:Listen tothy!                                  # read (numeric) input
You is the factorial ofyou!                         # take factorial
Open heart                                          # numeric output
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 2 bytes
```
:p
```
[Try it online!](https://tio.run/##y00syfn/36rg/39DAwA "MATL – Try It Online")
The `:` generates a range from 1 to input inclusive and the `p` reduces it on product
[Answer]
# C (gcc), 21 bytes
Uses the assignment trick, works consistently in GCC without optimizations.
```
O(o){o=o?o*O(~-o):1;}
```
[Try it online!](https://tio.run/##S9ZNT07@/99fI1@zOt823z5fy1@jTjdf08rQuvZ/Zl6JQm5iZp5GWX5miqZCNRdnWn6RggZIOFPBVsHAGkjZ2CoYghja2mAFnAVFQOk0DSXVFEWgEtWUmDwlHYVMHQV/jUxNTWsuzlqu2v8A "C (gcc) – Try It Online")
[Answer]
# x86-16 / x87 machine code, 13 bytes
Binary:
```
00000000: d9e8 e308 518b f4de 0c59 e2f8 c3         ....Q....Y...
```
Listing:
```
D9 E8       FLD1                ; start with 1 
E3 08       JCXZ DONE           ; if N = 0, return 1 
        FACT_LOOP: 
51          PUSH CX             ; push current N onto stack
8B F4       MOV  SI, SP         ; SI to top of stack for N 
DE 0C       FIMUL WORD PTR[SI]  ; ST = ST * N 
59          POP  CX             ; remove N from stack 
E2 F8       LOOP FACT_LOOP      ; decrement N, loop until N = 0
        DONE: 
C3          RET                 ; return to caller
```
Callable function. Input **\$n\$** in `CX`, output **\${n!}\$** in `ST(0)`. Works for values of **\$n\$** up to `21` (before loss of precision).
*Or recursive...*
## x86-16 / x87 machine code, 15 bytes
```
D9 E8       FLD1                ; start with 1
        FACT_CALL:
E8 0A       JCXZ DONE           ; if N = 0, end recursion
51          PUSH CX             ; push current N onto stack
49          DEC  CX             ; decrement N
E8 F9FF     CALL FACT_CALL      ; recurse N-1
8B F4       MOV  SI, SP         ; SI to top of stack for N
DE 0C       FIMUL WORD PTR[SI]  ; ST = ST * N
59          POP  CX             ; remove N from stack
        DONE:
C3          RET                 ; return from recursive call
```
*Or x64 just for grins...*
## x86\_64 machine code, ~~12~~ 11 bytes
```
  31:   6a 01            push   0x1             # start with 1
  33:   58               pop    rax
  35:   e3 05            jrcxz  3c <done>       # if 0, return 1
0037 <f_loop>:
  37:   48 f7 e1         mul    rcx             # rax = rax * N
  3a:   e2 fb            loop   37 <f_loop>     # loop until N = 0
003c <done>:
  3c:   c3               ret                    # return to caller
```
[Try it online!](https://tio.run/##ZVHtatwwEPwdPcWQo5C0V3MppRRDnqQ9gs6SHRV9uNIq5/Tl3ZXkS47WYFsfs7OzMzIl7U729fM0DGtnPGn7lF49yQU@zFGPZhGdXkhHjzny/Sg6JUmK0VGPLhGfTbj9YG3@6W9FR4x9K5AUjOgmG04WThovyqcXO5BOxHRhitJhCErjpG04C/DjwguiMnv8iMl8@n682THCOekVrPEaMk4JFAqm4gdpbe2EG4ZGFv6I3@cQFYyfM@FF2qzfmBGHZV9QBasMY0vFXQUhjHD376Tjt6@Vs23kQCEaaeu91RKbSjbiWI6w2wzCZsoYopN01TmZ2hnY4FGnbKnOkkyBI2RiyVclksUe3hW1BkVTW92xScoc9xu3WnD/bzHKoJoyx9GIeMMJaLbzvxTWXfOsh@dFsYqRTVNf6C5ZsjGC377yzTk946EalUhGwtkQH7S7MFcddfOL@f5ABc6wgM2Iw/4i7UGMTzaEuVG6bGtQV4mW78eqqNrPULSKMl/9Z0/G1qpHpitt@su8jad1YreLlTquYl2/HP4C "Assembly (gcc, x64, Linux) – Try It Online")
Input **\$n\$** in `rcx`, output **\${n!}\$** in `rax` for values of **\$n\$** up to `20`.
* -1 bytes thx to @PeterCordes on x86\_64!
[Answer]
## [Google Sheets](https://docs.google.com/spreadsheets/u/0/) / Excel / Numbers, 8 bytes
```
=FACT(A1
```
All three spreadsheet programs close parentheses automatically.
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), 56 bytes
```
+>,[[>+>+<<-]>[-<<[->+<<+>]<[->+<]>>>]<<[-]>[->+<]>>-]<.
```
[Try it online!](https://tio.run/##SypKzMxLK03O/v9f204nOtpO207bxkY31i5a18YmWhfE0baLhbBi7eyATCAbJAvh68ba6P3/zwoA "brainfuck – Try It Online")
Takes input and outputs as byte values. Since this interpreter has 8 bit size cells, it can't really do anything larger than `5!`. You can use [this interpreter](https://copy.sh/brainfuck/?c=Kz4sW1s-Kz4rPDwtXT5bLTw8Wy0-Kzw8Kz5dPFstPis8XT4-Pl08PFstXT5bLT4rPF0-Pi1dPAoKCls-KysrKysrKysrKzwgIFstPi1bPis-Pl0-WytbLTwrPl0-Kz4-XTw8PDw8XSAgPlstXT4rPl0gPFs-KysrKysrWy08KysrKysrKys-XTwtLjw8PF0$) to try larger values.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 29 bytes
```
.+
*
.
$.<'$*
~`.+
.+¶$$.($&_
```
[Try it online!](https://tio.run/##K0otycxLNPz/X0@bS4tLj0tFz0ZdRYurLgHI19M@tE1FRU9DRS3@/39DAwA "Retina – Try It Online") Explanation:
```
.+
*
```
Convert `n` to unary.
```
.
$.<'$*
```
Count down from `n` in decimal, with trailing `*`s.
```
~`.+
.+¶$$.($&_
```
Wrap the result in a Retina replacement stage and evaluate it.
Example: For `n=10`, the resulting stage is as follows:
```
.+
$.(10*9*8*7*6*5*4*3*2*1*_
```
This calculates the length of the string obtained by repeating the `_` by each of the numbers from `1` to `10`.
Explanation for `n=0`:
```
.+
*
```
Delete the input.
```
.
$.<'$*
```
Do nothing.
```
~`.+
.+¶$$.($&_
```
Do nothing, and evaluate the resulting empty stage on the empty string.
The empty stage returns `1` more than the character count. As the string is empty, this is just `1`. Conveniently, this is the result we wanted all along.
It is of course possible to calculate the factorial properly even for `n=0`, but my best attempt took 30 bytes.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 11 bytes
```
Gamma[#+1]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773z0xNzcxWlnbMFbtf0BRZl6Jgr5Dur5DUGJeeqqDodH//wA "Wolfram Language (Mathematica) – Try It Online")
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 15 bytes
```
1~Pochhammer~#&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n27737AuID85IyMxNze1qE5Z7X9AUWZeiYK@Q7q@Q1BiXnqqg6HR//8A "Wolfram Language (Mathematica) – Try It Online")
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 19 bytes
```
If[#>0,#0[#-1]#,1]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773zMtWtnOQEfZIFpZ1zBWWccwVu1/QFFmXomCvkO6vkNQYl56qoOh0f//AA "Wolfram Language (Mathematica) – Try It Online")
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 24 bytes
The determinant of the n\*n matrix of reciprocals of beta functions is n!
```
Det[1/Beta~Array~{#,#}]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773yW1JNpQ3ym1JLHOsagosbKuWllHuTZW7X9AUWZeiYK@Q7q@Q1BiXnqqg6HR//8A "Wolfram Language (Mathematica) – Try It Online")
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 26 bytes
```
GroupOrder@*SymmetricGroup
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n277370ov7TAvygltchBK7gyNze1pCgzGSz4P6AoM69EQd8hXd8hKDEvPTXaQMfQKPb/fwA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [///](https://esolangs.org/wiki////), 80 bytes
```
/!1/1!//!/S'SS'.'//1/S.B'S.B|B'SS.B|S|.SS'B|S'SS|B.SxBxSSxBxS|B..S//B/\\//S/\//!
```
Takes input in unary as `1`s appended to the program. Produces output in unary as `.`s.
[Try it online!](https://tio.run/##HYkhDsAwDAPfEhQWK1/IF0xLBiYNjJUU9O@pN0u@k@X5XvO5ZzcskQYY6KSHAwlGubrFT9yhS9bcFVy1@EMjCBTGAAjBUuk@ "/// – Try It Online")
The program sends the `!` to the end of the input, then makes several more substitutions. After completing the substitutions that exist in the initial program, each `1` from the input has been replaced with the following "1 code" (line breaks added for clarity):
```
/.\"/.\|\"/
/.\|/|./
/"\|/"/
/|\./x\x/
/x\x/|\../
```
and after that, `/'//'.'`.
Each copy of the "1 code" multiplies the number of full stops between the single quotes by 1, then increases the multiplier of the subsequent copies by 1. Many backslashes have been used to ensure that the rest of the code is not modified by earlier copies' execution.
The multiplication is done by adding a `|` at the end, then moving it left, replacing each `.` it passes with `.`, then removing it. To increase the multiplier, `|.` is changed to `|..`, with the intermediate step of `xx`.
Finally, the last substitution removes the single quotes, and the result is printed.
[Answer]
# [MAWP](https://esolangs.org/wiki/MAWP), 19 bytes
```
@[!1A]%_1A[%W_1A]~:
```
[Try it!](https://8dion8.github.io/MAWP/v1.1?code=%40%5B!1A%5D%25_1A%5B%25W_1A%5D%7E%3A&input=10)
[Answer]
# TI-BASIC (TI-83), 2 bytes
```
Ans!
```
Takes input via [`Ans`](https://codegolf.meta.stackexchange.com/a/8580/92901). The character count differs from the byte count because TI-BASIC is [tokenised](http://tibasicdev.wikidot.com/tokens); `Ans` and `!` are both 1-byte tokens.
### Sample output
Uses [this emulator](https://www.cemetech.net/sc/).
[![enter image description here](https://i.stack.imgur.com/SDhmM.png)](https://i.stack.imgur.com/SDhmM.png)
[Answer]
# [Rattle](https://github.com/DRH001/Rattle), ~~23~~ 20 bytes
```
|s>s[0+q][g-s<*~s>]~
```
[Try it online!](https://tio.run/##7Tz9cxu3jr/rr6BXl0RrS7Ikp02rxkmcxHn1TCbOJO7r3NjK61qipH1Z7Sr7Ecd9vvzrPQAkd0kuV7L7cW9u7jytIpEgCIIgAIIg19f5MokPfmuf/XjynsF/Zz8esxenL4/Zq9N39OPkzdnxu7fvjuFzhx3//fjN2U9Hr1//J6MGr4/e/O2no78ds59PXr9mz4/Z0cuXxy/Z2Sk7Ozllp2/Yydl7dvrzm51Wq816uz02TWZhvBizIp/3vsOSlud5r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This is the answer that I could not post on the other challenge! (see [this](https://codegolf.meta.stackexchange.com/questions/19208/should-we-remove-unnecessary-restrictions-on-the-factorial-challenge/19220#19220))
Note that I do not have an online interpreter for Rattle yet so the interpreter is mashed together into the header on TIO (which is why TIO thinks it's Python 3 code but what's in the `code` section is only Rattle code - ignore the header and footer).
This actually works for up to `170!` (but will a loss of precision, of course). In the next Rattle update this will actually become a builtin - making the possible solution just two bytes - but for its current version this is likely the shortest and most interesting factorial program.
# Explanation
```
|           takes user's input
s>s         saves the input to memory slots 0 and 1
[0+q]       if the top of the stack is equal to zero: increments, and quits (implicitly prints the top of the stack)
[    ]~     loop n times, where n is the value in storage at the pointer
 g-s         gets the value at the pointer, decrements, and saves
 <           moves pointer left
 *~          pushes product of old top of stack and value at pointer to new top of stack
 s           saves to memory slot at pointer
 >           moves pointer right
             (implicitly outputs the value at the top of the stack after the program executes)
```
In essence, this program saves the given value (from input) to two memory slots. Then, it decrements one memory slot and multiplies the other by the decremented value, until the value decrements to 1, then it outputs the final value.
[Answer]
# [Java](https://en.wikipedia.org/wiki/Java_(programming_language)), ~~37~~ 36 bytes
```
int f(int n){return n<2?1:n*f(n-1);}
```
I simply wanted to try to participate although Java is not the best language to have as little bytes as possible.
This is simply the definition coined to Java, with a recursive call.
edit: one byte less, thx @Jo King
[Answer]
# [Miniflak](https://esolangs.org/wiki/Miniflak), ~~90~~ 80 bytes
*-10 bytes thanks to @Nitrodon!*
```
{(({})[()])}{}((())){({(()[{}]({}))([{}]({}))}({}{})[{}])(({}({}))[({}[{}])])}{}
```
[Try it online!](https://tio.run/##PYwxDoBACAS/s1tY@hpyxV1hYjQWthvejkBhM4FZ2PXO89mOe14RAuQ0cNDlAEgKaWnyURnxT56s69xZfy0t2aYbIvYP)
We already have [another Brain-Flak answer](https://codegolf.stackexchange.com/a/210091/95679) here, but it uses both stacks and so doesn't work in Miniflak (a restricted subset of Brain-Flak where `<`, `>` and `[]` are disallowed). To avoid the second stack, this program uses a different multiplication algorithm.
### Explanation
```
{(({})[()])}
{          }    # While the top of the stack is nonzero:
   {}           # Pop the stack
  (  )          # Push a copy on the stack
      [()]      # Subtract 1
 (        )     # Push the result
```
This part counts down from the input value to 0, leaving a copy of each number in order.
  
```
{}((()))
{}              # Pop the zero on the top
  ((()))        # Push 1 twice
```
These extra ones are there so that when the input is 0 or 1, we multiply them together to get 1 instead of accidentally multiplying something by 0.
  
```
{({(()[{}]({}))([{}]({}))}({}{})[{}])(({}({}))[({}[{}])])}{}
{                                                        }    # While the top of the stack is nonzero:
 ({(()[{}]({}))([{}]({}))}({}{})[{}])                         # Multiply the top two values
                                     (({}({}))[({}[{}])])     # Swap the top two values
                                                          {}  # Remove the zero on top
```
This loop is the core of the program: at each step, it multiplies the top two numbers together and then brings the number below them to the top. When we run out of numbers, a zero gets swapped to the top, and the loop ends. We then remove that zero, and the result of multiplying all the numbers together (which is the factorial of the input, as the numbers counted down from it to 1) is left.
  
How does this multiplication algorithm work?
  
(Suppose the top two numbers on the stack are `a` and `b`.)
```
({(()[{}]({}))([{}]({}))}({}{})[{}])
      {}                               # Pop a
     [  ]                              # Subtract it ... 
   ()                                  # ... from 1
         ({})                          # Add b
  (          )                         # Push the result
               [{}]                    # Subtract that ... 
                   ({})                # ... from b ...
              (        )               # and push the result
 {                      }              # Repeat until a reaches 0, keeping a running total of the sum of both results
                          {}{}         # Pop a and b, add them together, ... 
                         (    )[{}]    # ... and ignore the result
(                                  )   # Push the running total
```
During each run-through, `a` (the top of the stack) is replaced by `b-(b+(1-a))`, which equals `a-1`. This repeats until `a` reaches 0, so the number of iterations is equal to the first input. The running total keeps track of the sum of the two results at each iteration. The first result is `b+(1-a)` and the second is `a-1`, so their sum is always `b`, the second input. This means that keeping track of the running total yields the product of the two inputs. Finally, before pushing the product, we pop `a` and `b` because we don't need them anymore.
  
The last piece is the swapping algorithm:   
```
(({}({}))[({}[{}])])
  {}                  # Pop the top number
    ({})              # Add the second number
 (      )             # Push the result
           {}         # Pop the sum
              {}      # Pop the second number ... 
             [  ]     # ... and subtract it from the sum
          (      )    # Push the result (the first number) ...
         [        ]   # ... and subtract that from the previous result (the sum)
(                  )  # Push the final result (the second number)
```
Since the first number is pushed back before the second one, their order is swapped from before.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 17 bytes
```
y=x=>x?x*y(x-1):1
```
[Try it online!](https://tio.run/##bc5LCoAgAAXAfSfRwMj@BdZZwiQK0cgIPb21jdd2VrPP9@zkuR0XM3ZRMQbhxegnnwbiGacDj9IaZ7XKtF1JIDmlyVc4SAFSglQgNUgD0oJ0ID0Of9K45m87Pg "JavaScript (Node.js) – Try It Online")
[Answer]
# [CJam](https://sourceforge.net/projects/cjam/), 4 bytes
```
rim!
```
[Try it online](https://tio.run/##S85KzP3/vygzV/H/f1MA)
I'm sure there's other 4-bytes solutions, but I quite like how this makes an English word with punctuation, even if exclaiming "rim!" without context seems absurd.
[Answer]
# [QBasic](https://en.wikipedia.org/wiki/QBasic), 37 bytes
```
INPUT n
f=1
FOR i=1TO n
f=f*i
NEXT
?f
```
If `n` is zero, the for loop does nothing and 1 is output. Otherwise, the for loop runs over `i` from 1 up to and including the input number, multiplying the result by each `i`.
The values here are single-precision by default, which means that after 10! we start getting output in scientific notation. The values are still accurate for 11! and 12!, though (e.g. 12! gives `4.790016E+08`). At 13! we start to see rounding error (`6.227021E+09` for 6227020800). If we use a double-precision variable `f#` in place of `f` (+4 bytes), we get accurate results up to 21!.
[Answer]
# [Rust](https://www.rust-lang.org/), 20 bytes
```
|n|(1..=n).product()
```
[Try it online!](https://tio.run/##hdC7DoIwFAbgvU9Rt9NESW8U8MLIaxgVMA5WhTIJz47lEDeLHTr0/86f5jRd68ba0vvpZoHRN6H@uKp1MPa2BxFFB8uiZ/Mou4sDNk4x25GBED80uX2xpYWFTkm2yf2dQ@0fvk2ntq0ad6xeKyjP1xXUwBlbUyp8x@9c/Mkl5jKYK8xNMNfzvA6CeP6A5EFhUCQLIkERcx0mKRLN1UJNhkYZmaZhJHCjM1pQuFeVZcIsMlyvTjLOhUE3kPED "Rust – Try It Online")
[Answer]
# [Rust](https://www.rust-lang.org/), 27 bytes
Closure that takes `n` as its input. Thanks to madlaina
```
|n|(1..=n).fold(1,|f,x|f*x)
```
Sample wrapper program to call closure (111 bytes).
```
fn main(){let f=|n|(1..=n).fold(1,|f,x|f*x);print!("{}",f(std::env::args().nth(1).unwrap().parse().unwrap()));}
```
[Try it online!](https://tio.run/##RcjBCoMwDADQX3GeklEK9VjxYwo2m6BZSeMmWL89223H92SvakbcbWlhwHPN2tHUuEHwfmL09FpnCK6ROxrdDxyLLKw36M@rdwRV5xgzv2NM8qiAnvUJAf3OH0nl55KkZvgH4niZWRi@ "Rust – Try It Online")
# [Rust](https://www.rust-lang.org/), 104 bytes
```
fn main(){print!("{}",(1..=std::env::args().skip(1).next().unwrap().parse().unwrap()).fold(1,|f,x|f*x))}
```
[Try it online!](https://tio.run/##TcjBCoMwDIDhV5meklEC9VjwYQq2o2yLJalbQX32zONu//fLps0s8@0dCwPuVQq3Acb9HB14olnbEkLiTwhRHgpI@iwVPBKn3i5u/JVYr6hRNP0NpLy@FvDuyK4f@d4RTzPz0w8 "Rust – Try It Online")
Rust sure isn't built for golfing, but 'twas interesting to do so! Takes `n` via program arguments. Conveniently fails at `13!`
I'm certain a fair number of bytes can be shaved from this, possibly if the `unwrap()` calls can be eliminated using `?` and a `Result`.
[Answer]
# [ArnoldC](https://lhartikk.github.io/ArnoldC/), 409 bytes
```
IT'S SHOWTIME
HEY CHRISTMAS TREE f
YOU SET US UP 1
HEY CHRISTMAS TREE x
YOU SET US UP 0
GET YOUR ASS TO MARS x
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
STICK AROUND x
GET TO THE CHOPPER f
HERE IS MY INVITATION f
YOU'RE FIRED x
ENOUGH TALK
GET TO THE CHOPPER x
HERE IS MY INVITATION x
GET DOWN 1
ENOUGH TALK
CHILL
TALK TO THE HAND f
YOU HAVE BEEN TERMINATED
```
[Try it online!](https://tio.run/##dZAxT8QwDIX3/Iq33QoTc671Xaw2SYmdqzoiEBMCian/vjhXIRA6Nsv@3rOfnz7fP95enreN9SCQkGflSC7Qgi4UFo1eoIUIr27JFUKKKqgT7m9B6x/ozp2ttl6BF2Myoi9iWJ/BipRnx5h90jbyMjQUHseauoB8wmMlUc5J4FOPHzT4C0EDRevLTIVsGCP17JXGxZmmG@BLrqZarzeYyHi7N08TFUsTTAUWxAWcLqy@7dlTHmxy4ma6Okq5ngPUj8Mtn/Ufn31pn@dkj/rt0QUeR9fKb6vQou3fvcY6EiUolcjJ0vTb9vAF "ArnoldC – Try It Online")
Iterative approach, it just loops starting from the input number and decreasing it until it reaches 0.
[Answer]
# [convey](http://xn--wxa.land/convey/), 16 bytes
```
 }>-1
1@"v
^*",{
```
[Try it online!](https://xn--wxa.land/convey/run.html#eyJjIjoiIH0+LTFcbjFAXCJ2XG5eKlwiLHsiLCJ2IjoxLCJpIjoiOSJ9)
Loops over the input value until it reaches `0`. There may be a shorter way using the indices command (`/.`), but it seems to take up more logic than I want. Since the interpreter includes a handy-dandy gif maker, you can even see it in action.
[![!](https://i.stack.imgur.com/KmxME.gif)](https://i.stack.imgur.com/KmxME.gif)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 1 byte
```
!
```
[Try it online!](https://tio.run/##y0rNyan8/1/x////JgA "Jelly – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 1 byte
```
!
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/Ff9rcqUmZ@QrpClUWBka/QcA "J – Try It Online")
Works for APL too
[Answer]
# R, 15 bytes
```
gamma(scan()+1)
```
There is also `factorial` which appears to be allowable as a 9-byte solution.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 5 bytes
```
$*\,q
```
[Try it online!](https://tio.run/##K8gs@P9fRStGp/D/f0Oj/wA "Pip – Try It Online")
[Answer]
# [Mini-Flak](https://github.com/DJMcMayhem/Brain-Flak), 56 bytes
```
{(({}[()])({({}({}))[({}[({})()])]}{}{})[({})])}{}({}())
```
[Try it online!](https://tio.run/##SypKzMzTTctJzP7/v1pDo7o2WkMzVlOjGsgCIk3NaLAQkAUSjq2tBkKwGJBXC1aioan5/78FAA "Brain-Flak – Try It Online")
When golfing a fold operation in Brain-Flak, it is generally better to keep the stack small and use a "generator" than to push the entire list at once. I'm not exactly why this is true, but it typically works out that way. In this case, it avoids an entire swap operation, since the loop index can stay on top the whole time.
The other main optimization is to make the bottom of the stack equal the running total *minus 1*. This 1 has to be added back later, but this is shorter than pushing a 1 below the input at the beginning.
The multiplication algorithm here is a variant of the swap algorithm. Specifically, there are two equivalent swap algorithms: `(({}({}))[({}[{}])])` calculates B as `(A + B) - A`, while `(([{}]({}))([{}]{}))` calculates B as `(B - A) + A`. To use this in a multiplication loop, we can modify these to not destroy B, and also decrement A by 1. There are three ways to add a single `()` to decrement A:
* `([{}]()({}))([{}]({}))` evaluates to `B`.
* `([{}]({}))([{}()]({}))` evaluates to `B - 1`
* `({}({}))[({}[({})()])]` evaluates to `B + 1`
The latter is what we want, since B is one less than the factor I actually want to represent. By multiplying `A - 1` by `B + 1` and then adding `B`, we obtain `A(B+1) - 1` as desired.
```
# Running counter: A
# Running product: B+1
# Start main loop
{
  (
    # Subtract 1 from A
    ({}[()])
    # Multiply by B+1
    ({({}({}))[({}[({})()])]}
    # Add B to get A(B+1) - 1 and push
    {}{})
  # Cancel out product to push A-1 again
  [({})])
}{}
# Add 1 to get final result
({}())
```
[Answer]
# [jq](https://stedolan.github.io/jq/), 30 bytes
```
reduce(range(.)+1)as$i(1;.*$i)
```
[Try it online!](https://tio.run/##yyr8/78oNaU0OVWjKDEvPVVDT1PbUDOxWCVTw9BaT0slU/P/f1MA "jq – Try It Online")
My first jq answer.
I spent a while trying to get `while` and `foreach` to do my bidding. Thankfully this existed.
# [jq](https://stedolan.github.io/jq/), 38 bytes
```
def f(x):if x>0then x*f(x-1)else 1end;
```
[Try it online!](https://tio.run/##yyr8/z8lNU0hTaNC0yozTaHCzqAkIzVPoUILKKJrqJmaU5yqYJial2L9P01DT/O/KQA "jq – Try It Online")
A recursive function. `reduce` is a shorthand for a function like this.
[Answer]
# [Quipu](https://esolangs.org/wiki/Quipu), 64 bytes
```
\/1&1&0&2&
3&++[][][]
>>3&**1&/\
1&[]1&++
;;%%>>1&
3&4&1&??
??==
```
[Try it online!](https://tio.run/##zVltc9s2DP6uX4GqV0dKWjtuty9u7Kxpt1u3vt3au31Ish0j07ZWWdJEOqnP59/eASCpSH5JrKa52@WSWCT4AHgAgSSsIpGIr53OB6G0hHk2KyDKhhLiFPREms9KRjrOUhDpkAfjNJ9pJ2EerEgbXmVJIgpQ8ThVMBGXEnQGFxKkikQuh3AV6wkMK0JePM2zAuGy9kfUHkk3EKGQRZ3OtLhIZPtFUYj5yWw0koWXXfyDs/BWoB3yi5bpUMGLPF/oYr54nWpZ5IXEv8EHUSj8V8K3R0U2PZlrqYKTRE7aeZGN22OpeSgMw2UkdDRZREJJyGXPLP/5SyRzMqU/yIs41Uka@GYGZFFkRQ/8g1wSzFuplBjL0GOAWPagYkwJA/0BlEAVgRINDnDtOt7fBDeUX97P9PvRSTZDpzdjvstsYEYx8uaHy6UXJUIpWPEnmBr8HnzUuHYcllyuiYSOcgOx0PNcwqdJIcUQ@lAJzenvaabPvaEcgcjzZB4oJh5V8P@wZ4RPzV8WPkeEhXeJOaEZUPXgTaz0KVJDU@/iBDodmClMIEyneChTrVhc6cIodaDGjXNnURCyGLJSF7PAVZlCqlmiezVPjHvndf9Q3nhE8XkTp1LBKEO5aAILSDAMCJdAghPosvz39OVEFASRWFMwfvh06MUjCKy70GcnQySBRmltO5HpGN@VARxCq8VwwWEID/rgn/k@fiThqwmGFwKDeQSVdeFNkyUgz4XtWP05iTH9c4HhsRYe9KHLxphH1FtF52gloNGRVF7ZNEBiNK2jkXez6YUsKLhoqme4pTntlS67WEPvwO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u@3rDglYWl7JQx7j4jOiKPIjh2eLfU4@LaW3GWwF1aqgbcXUZFgrlgy9Iuz2pTVh8qIuWj@wj9haTxdzZDowS7pc3s3ilTAEwpbPC/5fc2CUBgInVvXtFIdP1GeexkqxNsP4EqKqanlzW9y7PdQaZJrNxhPcJMazKbWXaZOBzBFi1Fo@109SeVhulAggdYVirx4gTosb0982enJMdarA5Wusi5n0rqtdtSgbpWGj9H4p0j1tdgAuFYASuLvSvqgz8w1EGWgH7Pxt5GwTB1iL6bw4HXiYADpcpSgt2/QqUsudWs2cl9cKC9ubKlNsPUnMm/hLViDvte9NKiiV9falMFd5EnNW8NcswTU9LOeOnCRYbkLsM5Z0rpFl2WVeKsU4sNPmSwCSpwywBZdrb7llmdywJOLdhRbVCuXCW1EOEss/Dl8zX1luThqs7VrF9ZZ2S6WmWrt21GGB8gjlZDadcOhHXCDnAo8n5rTDB2jTPObnCjQmw0za0uKOO6viFS1WfPWAtLpiteT1IOAi5irYjeo2lgKDwItPMswWkW4CsIey@h65Vax88bZK2Jdm67zL4q0CZfpulSh3na0S5VZTk7CT9G3rgo6T9I1rvxBXvu9/Pet0W93WYetpy3vWOjg4PacfbzB41trf77Y6Z163dXrexRnv@fNHjwaDLsn9gEuOj73j437/K4Isv/74Hw "Scala – Try It Online")
I decided to try out Quipu for LYAL event, and it's pretty fun to [finagle](https://www.merriam-webster.com/dictionary/finagle) with. I originally had this answer on the other factorial question, not realizing that it was invalid due to overflow.
Ungolfed:
```
"0  1  2  3  4 
---------------"
 \/ 1& 1& 0& 2&
 3& ++ [] [] []
 >> 3& ** 1& /\
 1& [] 1& ++
 ;; %% >> 1&
 3& 4& 1& ??
 ?? ==
```
Thread 0 takes input, then jumps to thread 3 if `N > 0`, otherwise it sets its value to 1 and jumps to thread 3.
Thread 3 then takes the value of thread 0 (`N if N > 0, else 1`) and increments it by 1 (we'll call this `M`), then jumps to thread 1.
Thread 1 increments its value, which acts as the accumulator (`acc`), and if `acc == M`, it jumps to thread 4, otherwise it jumps to thread 2.
Thread 2 takes its value (`X`) and multiplies it by `acc`. If `X != 0`, it jumps back to thread 1, otherwise it sets `X` to 1 and jumps to thread 3.
Once `acc` reaches `M`, execution jumps to thread 4, which prints the value of thread 2.
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 61 bytes
```
0+1.
N+F:-nth1(N,_,_),Y is N-1,Y+G,(F is G*N->1>0;F<G,!,0>1).
```
[Try it online!](https://tio.run/##TY1LC4JAFEb38yuuQaDNVWaMCnoIutCdayUiJB8J5sg40c6/XjNE5PLw3XPuIEUnGnd8te83o9wjKY33bq/u3E7xilcHc2hHSF2OOU3Qjg0lq9QNeMAO8TFBC1nAHe@rwxKUfFaE8DlkdGsggxOsDe0M1UU36m1Ds9/GfUaIT/2/uKU7n82i@gWbuSGNEGohH4WyF1Np6cZUTv0CzyFGFwchPH3vm6qvZKEqKLpOyzclZKsT8BxACeDsAw "Prolog (SWI) – Try It Online")
[Steffan's answer](https://codegolf.stackexchange.com/a/251552/76162) is much shorter at 28 bytes, but this predicate was created to be as general as possible. It can be used to:
* Validate that N! = F (for example, `5+120` will succeed, `6+120` will fail)
* Calculate `N!` (`5+F` will bind `F` to `120`)
* Calculate `N` from `N!` (`N+120` will bind `N` to `5`)
	+ `N+1` has both `0` and `1` as possible values
	+ A non-factorial will fail the predicate
* Generate all `N`, `N!` pairs
The last section feels like it can be golfed, especially as it has both `0>1` as always true and `0<1` as always false, but I've been staring at it for a while and can't figure out anything better. Pity that [`\+!` doesn't work](https://stackoverflow.com/questions/32517857/behavior-of-cuts-in-negation).
[Answer]
# TypeScript Type System, ~~98~~ 99 bytes
```
type X<A,B=A>=B extends`1${infer R}`?R extends""?A:B extends A?X<B,X<R>>:`${A&string}${X<R,A>}`:"1"
```
[Try it at the TypeScript playground](https://www.typescriptlang.org/play?#code/PQKgBAZghgxgLgewE4EsoBswFowE5dgBGAnnAKYDOYIwAULXMQA5lgAaAPAIIA0AQgF4uAPgF8wZAB7kAdgBMKAAwCMAEgDeKGRDJIwAJQC+igPz6J0svIoAiGya4AucVNkKwXE5z49O+4cKOihpcAGQUcKgyAOaGGn48IsaONso29MDAYOQRYDBQFJT0jCxgACqUcAAMYALsHHbCtJlgrQB6JgzMrBURyrX1qTZNLe2dJT2VAEwDnKlpI1ljXaW9cADMsw3KO8PNS2AdK5MRACxb87uLrYedQA)
+1 byte to make `X<0>` work properly
I/O is unary strings.
[Go check out emanresu A's really clean golf of this!](https://codegolf.stackexchange.com/a/265550/108687) It uses pretty much the same formula but the execution is really great.
It took me a little over an hour to come up with and golf. It's pretty hard to explain but the gist of it is that `X<A>` does the factorial, and `X<A,B>` does multiplication. It figures out which is being used by making `B` default to `A` if not specified, and checking if `B extends A`. I was able to get it so short by combining the types for factorial and multiplication, since they shared a lot of boilerplate.
I also wrote a version that uses decimal I/O for ~~184~~ 175 bytes:
```
//@ts-ignore
type X<A,B=[]>=A extends 1[]?B extends[1,...infer R]?R extends[]?A:B extends A?X<A,X<R,R>>:[...A,...X<R,A>]:[1]:B extends{length:A}?X<B,B>["length"]:X<A,[...B,1]>
```
[Try it at the TypeScript playground](https://www.typescriptlang.org/play?ssl=3&ssc=1&pln=4&pc=163#code/FDD0oAQFwZwWgJYHMB2B7ATgU2FAngA5YAEAGgDwCCANAEIC8A2gLoB89lxWAHlFigBMYxAIwsA-LS69+QxiOoA6ZQhQAzLBmIAlZuO3S+gmBMoAuKTyNDilcRRoVt1ba1ZnGyxTS9PqlVmYPESDLGWMAbwAbfiQoAAszSgBfe3JaOlZGACIYlDj47KCHak9lDJDWEHwiYgAVLBgoAAZiejJyZtZicGkiAGMoUTBQYjGAPXFcQhIGppE2jpFu3p4BoZERseJJ6dq5qAAmRYpDldG1rEHiQ62JqZrZxqgAZhPyF-O+q6GANjudg8ZvVngAWd6gr6Xa6HUEA3aPEFNACs72RUO461Eh2a8KB+2ev3evwxWIA7Di8Xsnk0ye8yaSfsRkc1QbjevdgEA)
[@tjjfvi](https://codegolf.stackexchange.com/users/87606/tjjfvi) showed me this spectacular 153 byte version with I/O in decimal:
```
//@ts-ignore
type M<A,B,N=[]>=A extends[0,...infer A]?M<A,B,[...N,...B]>:N;type F<N,X=[],A=[0],L="length">=X[L]extends N?A[L]:F<N,[0,...X],M<[0,...X],A>>
```
[Try it at the TypeScript playground](https://www.typescriptlang.org/play?#code/PTAECME9QAQFwFYDMkDcCWAoTJ4GcBadAcwDsB7AJwFNM5IAHa0AWQB4BBAGgCEuA5ALwBtALoA+QR1DUAHnGqkAJnmEAGLgDpt6UkmqVQHUQH523PsO2b+W7TwkAufgG56TUADE2tgBojRLg4RNUCAGUEAIgAbRWI4AAtIyV9hMNE5BWU8UH4TDjTRR29bdTtNX0D2MutKoPFxbHdmABVqPDg1UEEvNjVxUBAZWSYAYzhQAEYcMFBQAD0TOkZW9rhJ7t7JgaG5MYnpobnF5Y82joAmTe8LnbA96nHQC5m5haXm0HO4AGZrth+d2G+1AADZXscPisvmsACz-WFAh5PC6wiHvU6rDoAVn+2KRI0eBwuanRJ0+31B-1BBJBAHYSWSoWc1nT-nTaUTQNi1LDSUcMUA)
]