All problems
Expected Return With Discount
Problem
Compute the discounted return of a reward sequence: G = sum over t of gamma^t * rewards[t]. An empty sequence returns 0.0.
Hint
Keep a running power of gamma instead of recomputing gamma ** t.
Test cases
case 1
in: [[1,2,3],0.5]
expected: 2.75
case 2
in: [[],0.9]
expected: 0
case 3
in: [[5,5],1]
expected: 10
case 4
in: [[9,9],0]
expected: 9
case 5
in: [[1,-1,1],0.9]
expected: 0.91
Starter codePython
def discounted_return(rewards, gamma):
# Your code here
pass5 test cases · run your code against them in the editor