Skip to content
DeepForgeby svx
All problems

Reward Machine Transition

Problem

Step a reward machine given the current state and an observed event.

transitions is a list of [state, event, next_state] triples. Return the matching next state, or -1 when no transition applies.

Hint

The first matching transition wins; an unmatched event returns -1.

Test cases

case 1
in: ["s0","e1",[["s0","e1","s1"],["s1","e0","s0"]]]
expected: "s1"
case 2
in: ["s1","e1",[["s0","e1","s1"],["s1","e0","s0"]]]
expected: -1
case 3
in: [0,1,[[0,1,2],[2,0,0]]]
expected: 2
case 4
in: ["x","y",[]]
expected: -1
Starter codePython
def reward_machine_step(state, event, transitions):
    # Your code here
    pass

4 test cases · run your code against them in the editor