Skip to content
DeepForgeby svx
All problems
MediumCalculusca-081

Gamma Function Values

Problem

Evaluate the gamma function at positive integers and half-integers using the recursion Gamma(x + 1) = x * Gamma(x) with base values Gamma(1) = 1 and Gamma(0.5) = sqrt(pi).

Reduce x by whole steps until x is 1 or 0.5, then return the accumulated product.

Hint

Gamma(n) = (n-1)! for integers, and each half-step multiplies by the preceding half-integer.

Test cases

case 1
in: [0.5]
expected: 1.7724538509055159
case 2
in: [5]
expected: 24
case 3
in: [2.5]
expected: 1.329340388179137
case 4
in: [1]
expected: 1
case 5
in: [3.5]
expected: 3.323350970447842
Starter codePython
def gamma_value(x):
    # Only integer and half-integer inputs are supported
    # Your code here
    pass

5 test cases · run your code against them in the editor