def run_episode(problem, policy, limit):
    """
    Executes an episode within 'env' following 'policy'
    :param problem: problem
    :param policy: policy to follow
    :param limit: maximum number of steps
    :return: reward
    """
    obs = problem.reset()
    done = False
    reward = 0
    s = 0
    while not done and s < limit:
        obs, r, done, _ = problem.step(policy[obs])
        reward += r
        s += 1
    return reward