All problems
Discounted Return List
Problem
Compute the discounted return-to-go G_t for every timestep.
G_t = rewards[t] + gamma * G_{t+1}, with the value after the last step equal to 0. Return a list of the same length as rewards; an empty episode returns [].
Hint
Sweep backwards and carry one accumulated return.
Test cases
case 1
in: [[1,2,3],0.5]
expected: [2.75,3.5,3]
case 2
in: [[0,0,1],0.9]
expected: [0.81,0.9,1]
case 3
in: [[],0.5]
expected: []
case 4
in: [[4],1]
expected: [4]
Starter codePython
def discounted_returns_list(rewards, gamma):
# Your code here
pass4 test cases · run your code against them in the editor