[Question]
  [
Create the shortest program or function that finds the [factorial](http://en.wikipedia.org/wiki/Factorial) of a non-negative integer.
The factorial, represented with `!` is defined as such
$$n!:=\begin{cases}1 & n=0\\n\cdot(n-1)!&n>0\end{cases}$$
In plain English the factorial of 0 is 1 and the factorial of n, where n is larger than 0 is n times the factorial of one less than n.
Your code should perform input and output using a standard methods.
**Requirements:**
* Does not use any built-in libraries that can calculate the factorial (this includes any form of `eval`)
* Can calculate factorials for numbers up to 125
* Can calculate the factorial for the number 0 (equal to 1)
* Completes in under a minute for numbers up to 125
The shortest submission wins, in the case of a tie the answer with the most votes at the time wins.
  
[Answer]
## Golfscript -- 12 chars
```
{,1\{)*}/}:f
```
---
### Getting started with Golfscript -- Factorial in step by step
Here's something for the people who are trying to learn golfscript. The prerequisite is a basic understanding of golfscript, and the ability to read golfscript documentation.
So we want to try out our new tool [golfscript](http://www.golfscript.com/golfscript/index.html). It's always good to start with something simple, so we're beginning with factorial. Here's an initial attempt, based on a simple imperative pseudocode:
```
# pseudocode: f(n){c=1;while(n>1){c*=n;n--};return c}
{:n;1:c;{n 1>}{n c*:c;n 1-:n;}while c}:f
```
Whitespace is very rarely used in golfscript. The easiest trick to get rid of whitespace is to use different variable names. Every token can be used as a variable (see the [syntax](http://www.golfscript.com/golfscript/syntax.html) page). Useful tokens to use as variables are special characters like `|`, `&`, `?` -- generally anything not used elsewhere in the code. These are always parsed as single character tokens. In contrast, variables like `n` will require a space to push a number to the stack after. Numbers are essentially preinitialized variables.
As always, there are going to be statements which we can change, without affecting the end result. In golfscript, everything evaluates to true except `0`, `[]`, `""`, and `{}` (see [this](http://www.golfscript.com/golfscript/builtin.html#!)). Here, we can change the loop exit condition to simply `{n}` (we loop an additional time, and terminate when n=0).
As with golfing any language, it helps to know the available functions. Luckily the list is very short for golfscript. We can change `1-` to `(` to save another character. At present the code looks like this: (we could be using `1` instead of `|` here if we wanted, which would drop the initialization.)
> 
> `{:n;1:|;{n}{n|*:|;n(:n;}while|}:f`
> 
> 
> 
It is important to use the stack well to get the shortest solutions (practice practice practice). Generally, if values are only used in a small segment of code, it may not be necessary to store them into variables. By removing the running product variable and simply using the stack, we can save quite a lot of characters.
> 
> `{:n;1{n}{n*n(:n;}while}:f`
> 
> 
> 
Here's something else to think about. We're removing the variable `n` from the stack at the end of the loop body, but then pushing it immediately after. In fact, before the loop begins we also remove it from the stack. We should instead leave it on the stack, and we can keep the loop condition blank.
> 
> `{1\:n{}{n*n(:n}while}:f`
> 
> 
> 
Maybe we can even eliminate the variable completely. To do this, we will need to keep the variable on the stack at all times. This means that we need two copies of the variable on the stack at the end of the condition check so we don't lose it after the check. Which means that we'll have a redundant `0` on the stack after the loop ends, but that is easy to fix.
This leads us to our optimal `while` loop solution!
> 
> `{1\{.}{.@*\(}while;}:f`
> 
> 
> 
Now we still want to make this shorter. The obvious target should be the word `while`. Looking at the documentation, there are two viable alternatives -- [unfold](http://www.golfscript.com/golfscript/builtin.html#/) and [do](http://www.golfscript.com/golfscript/builtin.html#do). When you have a choice of different routes to take, try and weigh the benefits of both. Unfold is 'pretty much a while loop', so as an estimate we'll cut down the 5 character `while` by 4 into `/`. As for `do`, we cut `while` by 3 characters, and get to merge the two blocks, which might save another character or two.
There's actually a big drawback to using a `do` loop. Since the condition check is done after the body is executed once, the value of `0` will be wrong, so we may need an if statement. I'll tell you now that unfold is shorter (some solutions with `do` are provided at the end). Go ahead and try it, the code we already have requires minimal changes.
> 
> `{1\{}{.@*\(}/;}:f`
> 
> 
> 
Great! Our solution is now super-short and we're done here, right? Nope. This is 17 characters, and J has 12 characters. Never admit defeat!
---
### Now you're thinking with... recursion
Using recursion means we *must* use a branching structure. Unfortunate, but as factorial can be expressed so succinctly recursively, this seems like a viable alternative to iteration.
```
# pseudocode: f(n){return n==0?n*f(n-1):1}
{:n{n.(f*}1if}:f # taking advantage of the tokeniser
```
Well that was easy -- had we tried recursion earlier we may not have even looked at using a `while` loop! Still, we're only at 16 characters.
---
### Arrays
Arrays are generally created in two ways -- using the `[` and `]` characters, or with the `,` function. If executed with an integer at the top of the stack, `,` returns an array of that length with arr[i]=i.
For iterating over arrays, we have three options:
1. `{block}/`: push, block, push, block, ...
2. `{block}%`: [ push, block, push, block, ... ] (this has some nuances, e.g. intermediate values are removed from the stack before each push)
3. `{block}*`: push, push, block, push, block, ...
The golfscript documentation has an example of using `{+}*` to sum the contents of an array. This suggests we can use `{*}*` to get the product of an array.
```
{,{*}*}:f
```
Unfortunately, it isn't quite that simple. All the elements are off by one (`[0 1 2]` instead of `[1 2 3]`). We can use `{)}%` to rectify this issue.
```
{,{)}%{*}*}:f
```
Well not quite. This doesn't handle zero correctly. We can calculate (n+1)!/(n+1) to rectify this, although this costs far too much.
```
{).,{)}%{*}*\/}:f
```
We can also try to handle n=0 in the same bucket as n=1. This is actual extremely short to do, try and work out the shortest you can.
> 
> Not so good is sorting, at 7 characters: `[1\]$1=`.
>  Note that this sorting technique does has useful purposes, such as imposing boundaries on a number (e.g. `[0\100]$1=)  
> 
>  Here's the winner, with only 3 characters: .!+
> 
> 
> 
If we want to have the increment and multiplication in the same block, we should iterate over every element in the array. Since we aren't building an array, this means we should be using `{)*}/`, which brings us to the shortest golfscript implementation of factorial! At 12 characters long, this is tied with J!
> 
> `{,1\{)*}/}:f`
> 
> 
> 
---
### Bonus solutions
Starting with a straightforward `if` solution for a `do` loop:
```
{.{1\{.@*\(.}do;}{)}if}:f
```
We can squeeze a couple extra out of this. A little complicated, so you'll have to convince yourself these ones work. Make sure you understand all of these.
```
{1\.!!{{.@*\(.}do}*+}:f
{.!{1\{.@*\(.}do}or+}:f
{.{1\{.@*\(.}do}1if+}:f
```
A better alternative is to calculate (n+1)!/(n+1), which eliminates the need for an `if` structure.
> 
> `{).1\{.@*\(.}do;\/}:f`
> 
> 
> 
But the shortest `do` solution here takes a few characters to map 0 to 1, and everything else to itself -- so we don't need any branching. This sort of optimization is extremely easy to miss.
> 
> `{.!+1\{.@*\(.}do;}:f`
> 
> 
> 
For anyone interested, a few alternative recursive solutions with the same length as above are provided here:
```
{.!{.)f*0}or+}:f
{.{.)f*0}1if+}:f
{.{.(f*}{)}if}:f
```
---
\*note: I haven't actually tested many of the pieces of code in this post, so feel free to inform if there are errors.
[Answer]
# Python - 27
Just simply:
```
f=lambda x:0**x or x*f(x-1)
```
[Answer]
## Haskell, 17
```
f n=product[1..n]
```
[Answer]
## APL (4)
```
×/∘⍳
```
Works as an anonymous function:
```
    ×/∘⍳ 5
120
```
If you want to give it a name, 6 characters:
```
f←×/∘⍳
```
[Answer]
# [Mornington Crescent](https://esolangs.org/wiki/Mornington_Crescent), 1827 1698 chars
I felt like learning a new language today, and this is what I landed on... (Why do I do this to myself?) This entry won't be winning any prizes, but it beats all 0 other answers so far using the same language!
```
Take Northern Line to Bank
Take Central Line to Holborn
Take Piccadilly Line to Heathrow Terminals 1, 2, 3
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Parsons Green
Take District Line to Bank
Take District Line to Parsons Green
Take District Line to Acton Town
Take District Line to Hammersmith
Take Circle Line to Aldgate
Take Circle Line to Aldgate
Take Metropolitan Line to Chalfont & Latimer
Take Metropolitan Line to Aldgate
Take Circle Line to Hammersmith
Take District Line to Acton Town
Take Piccadilly Line to Bounds Green
Take Piccadilly Line to Acton Town
Take Piccadilly Line to Bounds Green
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Parsons Green
Take District Line to Notting Hill Gate
Take Circle Line to Notting Hill Gate
Take Circle Line to Bank
Take Circle Line to Temple
Take Circle Line to Aldgate
Take Circle Line to Aldgate
Take Metropolitan Line to Chalfont & Latimer
Take Metropolitan Line to Chalfont & Latimer
Take Metropolitan Line to Aldgate
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take District Line to Upney
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upney
Take District Line to Bank
Take Circle Line to Embankment
Take Circle Line to Embankment
Take Northern Line to Angel
Take Northern Line to Moorgate
Take Metropolitan Line to Chalfont & Latimer
Take Metropolitan Line to Moorgate
Take Circle Line to Moorgate
Take Northern Line to Mornington Crescent
```
[Try it online!](https://tio.run/##xVXLbgIxDLz3K3zqiUp9fAHQqhwAcVg@IASXjUjsleMK8fU0aoEthX1AUXseZzz2TJLAQo4WynRnBaNF0s0mM0uEMYvmKARDRwjK0DO0vPmE@qlKjN8jA/azxPMFTpy1Zu68X5c4Gs2FV5ChBEfGR3jowGMHniqPdG2SBBmvtqzPLqo4q@0LJkYiU4RXQayqKUe66HijhoEJASUGp/l2c06sx5LAzxdGsRkboQoX7J2a0pB@bvwbk8ItDI261KmmuK7VkczGSU841uN3mh/sq4Wt1@I535pvaT53GdMihTjqbt0XRWfMqunewSCNBa9VxrSrqhwlw1B4/O/k/WFMm5ypue/TgnB9Ie3vhdV1r7T3JcwSFNJj3Ao@etC7tEBfgY2Y5ZohOOT7ofQQPKFl90dBf/9H3X8A)
Anyone who's journeyed around London will understand that instantly of course, so I'm sure I don't need to give a full explanation.
Most of the work at the start is in handling the 0 case. After initialising the product at 1, I can use that to calculate max(input, 1) to get the new input, taking advantage of the fact that 0! = 1! Then the main loop can begin.
(EDIT: A whole bunch of trips have been saved by stripping the 1 from "Heathrow Terminals 1, 2, 3" instead of generating it by dividing 7 (Sisters) by itself. I also use a cheaper method to generate the -1 in the next step.)
Decrementing is expensive in Mornington Crescent (although less expensive than the Tube itself). To make things more efficient I generate a -1 by taking the NOT of a parsed 0 and store that in Hammersmith for much of the loop.
---
I put some significant work into this, but since this is my first attempt at golfing in Mornington Crescent (in fact my first attempt in *any* language), I expect I missed a few optimisations here and there. If you're interested in programming in this language yourself (and why wouldn't you be?), [Esoteric IDE](https://github.com/Timwi/EsotericIDE/) - with its debug mode and watch window - is a must!
[Answer]
# [J](http://jsoftware.com/), 12 bytes
A standard definition in J:
```
f=:*/@:>:@i.
```
[Try it online!](https://tio.run/##y/r/P83WSkvfwcrOyiFT739qcka@QpqCocF/AA "J – Try It Online")
Less than 1sec for 125!
Eg:
```
 f 0
 1
 f 5
 120
  f 125x
 1882677176888926099743767702491600857595403
 6487149242588759823150835315633161359886688
 2932889495923133646405445930057740630161919
 3413805978188834575585470555243263755650071
 31770880000000000000000000000000000000
```
[Answer]
## Golfscript - 13 chars **(SYM)**
defines the function `!`
```
{),()\{*}/}:!             # happy robot version \{*}/ 
```
alternate 13 char version
```
{),()+{*}*}:! 
```
whole program version is **10 chars**
```
~),()+{*}*
```
testcases take less than 1/10 second:
**input:**
```
0!
```
**output**
```
1
```
**input**
```
125!
```
**output**
```
188267717688892609974376770249160085759540364871492425887598231508353156331613598866882932889495923133646405445930057740630161919341380597818883457558547055524326375565007131770880000000000000000000000000000000
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 2 bytes
```
:p
```
Explained:
```
:    % generate list 1,2,3,...,i, where i is an implicit input
p    % calculate the product of of all the list entries (works on an empty list too)
```
[Try it online!](https://tio.run/##y00syfn/36rg/3@T/wA "MATL – Try It Online")
[Answer]
## Perl 6: 13 chars
```
$f={[*]1..$_}
```
`[*]` is same as Haskell `product`, and `1..$_` is a count-up from 1 to `$_`, the argument.
[Answer]
# [Python 2](https://docs.python.org/2/), 28 bytes
```
f=lambda x:x/~x+1or x*f(x-1)
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P802JzE3KSVRocKqQr@uQtswv0ihQitNo0LXUPN/QVFmXolGmoahgabmfwA "Python 2 – Try It Online")
(based off Alexandru's solution)
[Answer]
# [Java (JDK)](http://jdk.java.net/), 85 bytes
```
BigInteger f(int n){return n<2?BigInteger.ONE:new BigInteger(""+n).multiply(f(n-1));}
```
[Try it online!](https://tio.run/##RY7BCsIwDIbve4qwU4sY1KMKguDBg3rwCarW2dlmo80mY@zZayfC/luSj/9LqVo1Lx/vaFxdeYYyzegUv3BviiOxLrTfZNndqhDgpAxBn0FKYMXmDnGi4CkMMZDsvebGE9B2tZvOeDkf1qQ/MK1Ens9Iomssm9p24ilovpRyM8TRUDc3mwx/UVuZB7jkF1f2hgpEBOWLIP//jLl2gbXDqmGsE8OWUuVykRp/yJAN8Qs "Java (JDK) – Try It Online")
[Answer]
# Matlab, 15
```
f=@(x)prod(1:x)
```
Test Cases
```
>> f(0)
ans =
     1
>> f(4)
ans =
    24
>> tic,f(125),toc
ans =
  1.8827e+209
Elapsed time is 0.000380 seconds.
```
[Answer]
# [F# (.NET Core)](https://www.microsoft.com/net/core/platform), 26 bytes
There's no inbuilt product function in F#, but you can make one with a [fold](http://en.wikipedia.org/wiki/Fold_(higher-order_function))
```
let f n=Seq.fold(*)1{1..n}
```
[Try it online!](https://tio.run/##SyvWTc4vSv3/Pye1RCFNIc82OLVQLy0/J0VDS9Ow2lBPL6/2f0FRZl5JWp6CkmqKkoJGmoahgabmfwA "F# (.NET Core) – Try It Online")
[Answer]
## JavaScript, 25
```
function f(n)!n||n*f(n-1)
```
## CoffeeScript, 19
```
f=(n)->!n||n*f(n-1)
```
Returns `true` in the case of n=0, but JavaScript will type-coerce that to 1 anyway.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 21 bytes
```
f=->n{n>1?n*f[n-1]:1}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y6vOs/O0D5PKy06T9cw1sqw9n9BaUmxQlq0oUHsfwA "Ruby – Try It Online")
## Test
```
irb(main):009:0> f=->n{n>1?n*f[n-1]:1}
=> #<Proc:0x25a6d48@(irb):9 (lambda)>
irb(main):010:0> f[125]
=> 18826771768889260997437677024916008575954036487149242588759823150835315633161
35988668829328894959231336464054459300577406301619193413805978188834575585470555
24326375565007131770880000000000000000000000000000000
```
[Answer]
# PostScript, 26 chars
```
/f{1 exch -1 1{mul}for}def
```
Example:
```
GS> 0 f =
1
GS> 1 f =
1
GS> 8 f =
40320
```
The function itself takes only 21 characters; the rest is to bind it to a variable. To save a byte, one can also bind it to a digit, like so:
```
GS> 0{1 exch -1 1{mul}for}def
GS> 8 0 load exec =
40320
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~7~~ 6 bytes
By making a range and multiplying it
-1 byte tanks to ovs having the idea to use the max() function
```
;1⌉⟦₁×
```
## Explanation
```
;1          --  If n<1, use n=1 instead (zero case)
  ⟦₁        --      Construct the range [1,n]
    ×       --      return the product of said range
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/39rwUU/no/nLHjU1Hp7@/7/p/ygA "Brachylog – Try It Online")
---
# [Brachylog](https://github.com/JCumin/Brachylog), ~~10~~ 9 bytes
recursion
```
≤1|-₁↰;?×
```
## Explanation
```
            --f(n):
≤1          --  if n ≤ 1: return 1
|           --  else:
 -₁↰        --      f(n-1)
    ;?×     --            *n
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r//1HnEsMa3UdNjY/aNljbH57@/7@hwf8oAA "Brachylog – Try It Online")
[Answer]
# Ruby - ~~30~~ 29 characters
```
def f(n)(1..n).inject 1,:*end
```
Test
```
f(0) -> 1
f(5) -> 120
```
[Answer]
# Javascript, ES6 17
```
f=n=>n?n*f(n-1):1
```
ES6:
* Arrow function
[Answer]
# C#, 20 or 39 characters depending on your point of view
As a traditional instance method (39 characters; [tested here](http://rextester.com/XER29007)):
```
double f(int x){return 2>x?1:x*f(x-1);}
```
As a lambda expression (20 characters, but see disclaimer; [tested here](http://rextester.com/HEAQRN39064)):
```
f=x=>2>x?1:x*f(x-1);
```
We have to use `double` because [125! == 1.88 \* 10209](http://www.wolframalpha.com/input/?i=125!), which is much higher than [`ulong.MaxValue`](https://msdn.microsoft.com/en-us/library/system.uint64.maxvalue(v=vs.110).aspx).
### Disclaimer about the lambda version's character count:
If you recursion in a C# lambda, you obviously have to store the lambda in a named variable so that it can call itself. But unlike (e.g.) JavaScript, a self-referencing lambda must have been declared **and initialized** on a previous line. You can't call the function in the same statement in which you declare and/or initialize the variable.
In other words, [this doesn't work](http://rextester.com/DEV6527):
```
Func<int,double> f=x=>2>x?1:x*f(x-1); //Error: Use of unassigned local variable 'f'
```
But [this does](http://rextester.com/JFV25693):
```
Func<int,double> f=null;            
f=x=>2>x?1:x*f(x-1);  
```
There's no good reason for this restriction, since `f` can't ever be unassigned at the time it runs. The necessity of the `Func<int,double> f=null;` line is a quirk of C#. Whether that makes it fair to ignore it in the character count is up to the reader.
# CoffeeScript, 21 19 characters for real
```
f=(x)->+!x||x*f x-1
```
**Tested here:** <http://jsfiddle.net/0xjdm971/>
[Answer]
# [Aheui (esotope)](https://github.com/aheui/pyaheui), ~~93~~ ~~90~~ 87 bytes
```
박밴내색뱅뿌뮹
숙쌕빼서빼처소
타뿌싼때산쑥희
매차뽀요＠어몽
```
[Try it online!](https://tio.run/##AWMAnP9haGV1af//67CV67C064K07IOJ67GF67@M6665CuyImeyMleu5vOyEnOu5vOyymOyGjArtg4Drv4zsi7zrlYzsgrDskaXtnawK66ek7LCo672A7JqU77yg7Ja066q9//8xMjU "Aheui (esotope) – Try It Online")
Nice, small, and fast code. Slightly golfed after writing explanation. I'll not change it, because it is just same code.
# Explaination
Aheui is befunge-like language and (almost) every character of Aheui is operator. Part of character looks like `ㅏ, ㅐ, ㅓ, ㅜ, ㅛ, ㅗ, ㅢ` determines direction where next operator execute. `ㅏ` is left-to-right, `ㅓ` is right-to-left, `ㅗ` is down-to-up, `ㅜ` is up-to-down, `ㅛ` is down-to-up, with skipping one character in two characters. `ㅐ` is 'nothing' : keep same speed and direction.
```
박밴내
```
`ㅂ` commend is store given number in current stack, `ㄴ` commend is divide upmost two number in current stack. Both `박` and `백` store 2, so `박밴내` store 1 in current stack(default `아` or `nothing` stack)
```
색뱅
```
`ㅅ` commend change current stack. `색` change stack to `악` (or `ㄱ`) stack. `ㅂ` commend with `ㅇ` (like `뱅` or `방`) get a number from STDIN. So `색뱅` get a number and store it in stack `악(ㄱ)`.
```
뿌
처
```
`ㅃ` commend duplicate upmost value in current stack, and `ㅊ` commend pop value from current stack and see if it is 0. If it is, it go to opposite direction from `ㅓ` indicate : in here right-to-left. If it is not, it go to direction where `ㅓ` indicate. So `뿌(\n)처` see if input is 0 or not, and go right if zero, and go left if not.
```
망희
소
```
If input is zero, here is evaluated. (from `소` commend) First, change current stack to `nothing`(`아`). `ㅁ` commend is pop, and if used with `ㅇ` it print value as number. `희` halts program. So it print 1 and halt.
```
숙쌕빼서빼
타뿌싼때산쌕꾸
매차뽀요애애어
```
[![enter image description here](https://i.stack.imgur.com/PA8hr.png)](https://i.stack.imgur.com/PA8hr.png)
Look at this image for help. Here is main loop.
`ㅌ` is subtraction, and `ㄸ` is multiply. `ㅆ` move value from current stack to selected one.
Put it shortly, it get number from `nothing` stack(or get 1), subtract to find if it is zero, and if not zero multiply and restart loop.
And if zero, go to rightmost place of code with popping one number.
```
몽
```
Print number, then pointer go to `희` : halt.
In one image :
[![AheuiChem image translated](https://i.stack.imgur.com/8nfNl.png)](https://i.stack.imgur.com/8nfNl.png)
SEL is select, MOV is move, DUP is duplicate. This image is produced by [AheuiChem](http://yoo2001818.github.io/AheuiChem/), Aheui development tool in Korean. Translated with paint tool of windows.
[Answer]
# [8088](https://en.wikipedia.org/wiki/Intel_8088) / [8087](https://en.wikipedia.org/wiki/Intel_8087) machine code, 13 bytes
```
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
```
Input **\$n\$** is in `CX`, output **\${n!}\$** is in `ST(0)`.
Test output displayed using Borland Turbo Debugger 3:
**n = 1:**
[![enter image description here](https://i.stack.imgur.com/M46YW.png)](https://i.stack.imgur.com/M46YW.png)
**n = 15:**
[![enter image description here](https://i.stack.imgur.com/3pLeB.png)](https://i.stack.imgur.com/3pLeB.png)
**n = 50:**
[![enter image description here](https://i.stack.imgur.com/TsvIA.png)](https://i.stack.imgur.com/TsvIA.png)
**n = 125:**
[![enter image description here](https://i.stack.imgur.com/LVXDC.png)](https://i.stack.imgur.com/LVXDC.png)
**Notes:**
* Calculates \${125!}\$ in an imperceptible amount of time (difficult to accurately profile in DOS)
* Language is not newer than the challenge
[Answer]
# C (39 chars)
```
double f(int n){return n<2?1:n*f(n-1);}
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 2 bytes
```
RP
```
[Try it online!](https://tio.run/##y0rNyan8/z8o4P///6YA "Jelly – Try It Online")
Alternatively, a builtin answer is one byte:
```
!
```
[Try it online!](https://tio.run/##y0rNyan8/1/x////pgA "Jelly – Try It Online")
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 45 bytes
```
x=input();forstep(y=x-1,1,-1,x=x*y);print(x);
```
[Try it online!](https://tio.run/##K0gsytRNL/j/v8I2M6@gtERD0zotv6i4JLVAo9K2QtdQx1AHSFTYVmhValoXFGXmlWhUaFr//w8A "Pari/GP – Try It Online")
[Answer]
# D: 45 Characters
```
T f(T)(T n){return n < 2 ? 1 : n * f(n - 1);}
```
More legibly:
```
T f(T)(T n)
{
    return n < 2 ? 1 : n * f(n - 1);
}
```
A cooler (though longer version) is the templatized one which does it all at compile time (**64 characters**):
```
template F(int n){static if(n<2)enum F=1;else enum F=n*F!(n-1);}
```
More legibly:
```
template F(int n)
{
    static if(n < 2)
        enum F = 1;
    else
        enum F = n * F!(n - 1);
}
```
Eponymous templates are pretty verbose though, so you can't really use them in code golf very well. D's already verbose enough in terms of character count to be rather poor for code golf (though it actually does *really* well at reducing overall program size for larger programs). It's my favorite language though, so I figure that I might as well try and see how well I can get it to do at code golf, even if the likes of GolfScript are bound to cream it.
[Answer]
## PowerShell – 36
Naïve:
```
filter f{if($_){$_*(--$_|f}else{1}}
```
Test:
```
> 0,5,125|f
1
120
1,88267717688893E+209
```
[Answer]
## Scala, 39 characters
```
def f(x:BigInt)=(BigInt(1)to x).product
```
Most of the characters are ensuring that `BigInt`s are used so the requirement for values up to 125 is met.
[Answer]
## PowerShell, 42 bytes
(saved 2 chars using *filter* instead of *function*)
```
filter f($x){if(!$x){1}else{$x*(f($x-1))}}
```
Output:
```
PS C:\> f 0
1
PS C:\> f 5
120
PS C:\> f 1
1
PS C:\> f 125
1.88267717688893E+209
```
[Answer]
# Racket (scheme) 40 35 29 bytes
Computes 0! to be 1, and computes 125! in 0 seconds according to timer. Regular recursive approach
```
(define(f n)(if(= n 0)1(* n(f(- n 1)))))
```
New version to beat common lisp: multiplies all elements of a list (same as that Haskell solution)
```
(λ(n)(apply *(build-list n add1)))
```
Newer version to beat the other scheme solution and math the other racket solution by using foldl instead of apply and using range instead of buildlist
```
(λ(n)(foldl * n(range 1 n)))
```
]