# Challenge

The objective is simple, in the shortest amount of bytes, write a function or program that takes a number and prints its double factorial.

The input must be taken from stdin or a function argument, and it must print the resulting double factorial to stdout.

Inbuilts are disallowed

• What makes this significantly different from Find the factorial? Most approaches will be the same IMO. – Geobits Jan 20 '15 at 18:10
• @Geobits The approach has to be different, due to the additional requirement of only getting the product of the numbers up to n with the same parity. – globby Jan 20 '15 at 18:12
• @globby No, I think I blame you for changing the rules to disallow an existing answer... which could have been avoided by posting the challenge in the sandbox first, where someone certainly would have pointed out that loophole. – Martin Ender Jan 20 '15 at 18:29
• I waited to VTC as dupe until I saw a few answers, but the current ones only reassure me that most answers here will simply be a couple chars different from the standard factorial. – Geobits Jan 20 '15 at 18:41
• If the question does not call out that REPL is not accepted, a JS answer without alert or haskell one without print is totally acceptable – Optimizer Jan 20 '15 at 18:49

p n=product[n,n-2..1]

• @MartinBüttner: It does. At least within ghci. – nimi Jan 20 '15 at 18:38
• I can argue that my function without the alert prints to console when run from console. – Optimizer Jan 20 '15 at 18:39
• @Optimizer: Sure. Why not? Some languages provide or run in interactive environments (aka repl). Use it! – nimi Jan 20 '15 at 18:43
• – Martin Ender Jan 20 '15 at 18:49

# CJam, 13 12 bytes

ri,:)1~%1+:*


Expanded code:

ri            "Read the input as a string and convert it to integer";
,           "Create an array of 0 to input integers - 1";
:)         "Increment each element in the array";
1~       "Put 1 and do bitwise not to get -2";
%      "Take every other integer starting from end";
1+    "Add 1 to the array to account for result of 0 being 1";
:*  "Reduce product to get double factorial";


At the end of the code, anything on stack is automatically printed to STDOUT in CJam.

Try it online here

# JavaScript, ES6, 38 36 bytes

Wow this is huge!

f=a=>alert((g=n=>n>1?n*g(n-2):1)(a))
<input id=D /><button onclick="f(+D.value)">Run</button>

Of course I am just counting JS code. HTML is just for stack snippet demo.

Run it in latest Firefox browser.

# Matlab 16

@(n)prod(n:-2:1)


It is pretty sraight forward.

## r, 30

f=function(n)prod(seq(n,1,-2))


# Pyth: 11 character

u*GhH%2_UQ1


Q is the input value. UQ creates the list [0, 1, 2, ..., Q-1], _ inverts it, and %2 removes every other element [Q-1, Q-3, Q-5, ..., (1 or 0)]. u*GhH...1 reduces the list by multiplying the list elements (increased by 1) to 1.

Try it here: Pyth Compiler/Executor