Editor

Double Factorial

#542 · Loops · Beginner · 30 XP · about 4 min

The double factorial of n, written n!!, multiplies n by every second number below it, down to 1 or 2:

  • 7!! = 7 x 5 x 3 x 1 = 105
  • 8!! = 8 x 6 x 4 x 2 = 384

Write double_factorial(n) that returns n!!. Mathematicians agree that 0!! and 1!! are both 1.

Examples

double_factorial(7)  # returns 105
double_factorial(8)  # returns 384
double_factorial(0)  # returns 1

Note

n is a whole number from 0 to 100.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.