Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/numpy_pandas/numerical_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ def numerical_integration_rectangle(


def binomial_coefficient_recursive(n: int, k: int) -> int:
# Use a cache to store previously computed results for faster lookups
if not hasattr(binomial_coefficient_recursive, "_cache"):
binomial_coefficient_recursive._cache = {}
cache = binomial_coefficient_recursive._cache
key = (n, k)
if key in cache:
return cache[key]
if k == 0 or k == n:
return 1
return binomial_coefficient_recursive(
n - 1, k - 1
) + binomial_coefficient_recursive(n - 1, k)
result = 1
else:
result = binomial_coefficient_recursive(
n - 1, k - 1
) + binomial_coefficient_recursive(n - 1, k)
cache[key] = result
return result


def naive_matrix_determinant(matrix: List[List[float]]) -> float:
Expand Down