Skip to content

Commit 9395ddd

Browse files
committed
fix: resolve #14886 - add validation for non-power-of-2 scores in minimax
1 parent 9af513a commit 9395ddd

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

backtracking/minimax.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def minimax(
5757
if len(scores) == 0:
5858
raise ValueError("Scores cannot be empty")
5959

60+
# Validate that scores length is a power of 2
61+
if len(scores) & (len(scores) - 1) != 0:
62+
raise ValueError("Number of scores must be a power of 2")
63+
6064
# Base case: If the current depth equals the height of the tree,
6165
# return the score of the current node.
6266
if depth == height:
@@ -92,4 +96,4 @@ def main() -> None:
9296
import doctest
9397

9498
doctest.testmod()
95-
main()
99+
main()

0 commit comments

Comments
 (0)