PIXELBANKv9.1.0
Menu

Problem Statement

Policy iteration stops when the policy no longer changes. Given two deterministic policies old and new (lists of action indices), return True if they are identical (policy is stable), else False.

Implement policy_stable(old, new).

Example:

Input:
policy_stable([0, 1, 1], [0, 1, 1])
Output:
True
Reasoning:
  • We begin by identifying the two deterministic policies provided in the input: the old policy is the list [0,1,1][0, 1, 1] and the new policy is the list [0,1,1][0, 1, 1].
  • To check for stability, we compare the actions at each state index ii from 00 to 22 to ensure the old and new policies are identical.
  • At index 00, we compare the first elements: 0=00 = 0, which matches.
  • At index 11, we compare the second elements: 1=11 = 1, which matches.
  • At index 22, we compare the third elements: 1=11 = 1, which matches.
  • Since all corresponding elements are equal, the policies are identical, indicating the policy has converged; the final output is True

Constraints:

  • len(old) == len(new).
  • Return a Python bool.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Policy Stability Check - Easy | PixelBank