PIXELBANKv9.1.0
Menu

Effective Horizon of a Discount Factor

Problem Statement

The effective planning horizon implied by a discount factor is often summarized as 1 / (1 - gamma) β€” the sum of the geometric discount series sum_{t=0}^inf gamma^t. For gamma == 1 the horizon is infinite; represent that with float('inf').

Implement effective_horizon(gamma) returning a float.

Example:

Input:
effective_horizon(0.9)
Output:
10.0
Reasoning:
  • Check if the discount factor Ξ³=0.9\gamma = 0.9 is greater than or equal to 1.01.0 to determine if the horizon is infinite; since 0.9<1.00.9 < 1.0, the horizon is finite.
  • Calculate the denominator of the geometric series sum by subtracting the discount factor from 11: 1.0βˆ’0.9=0.11.0 - 0.9 = 0.1.
  • Compute the effective horizon by dividing 11 by this denominator: 1.0/0.1=10.01.0 / 0.1 = 10.0.
  • The final output is 10.0

Constraints:

  • 0.0 <= gamma <= 1.0
  • gamma == 1.0 returns float('inf').
  • Otherwise return 1 / (1 - gamma).
πŸ”’

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Effective Horizon of a Discount Factor - Medium | PixelBank