def compute_discounted_return(gamma, rewards):
    """
    Args:
        gamma: discount factor.
        rewards: List of reward for the episode

    Returns: $\Sum_{t=0}^T \gamma^t r_t$

    """
    discounted_return = 0
    discount = 1
    for reward in rewards:
        discounted_return += reward * discount
        discount *= gamma
    return discounted_return