Open the context
Choose the project folder and name the files or behavior involved.
Choose a winning reduction for normal-play Nim from at most 128 piles of zero through one billion objects. Test all-zero and losing positions, returning no move when the xor is zero and rejecting negative or Boolean pile sizes.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def nim_move(piles):
if type(piles) not in (list, tuple) or len(piles) > 128 or any(type(v) is not int or not 0 <= v <= 10**9 for v in piles):
raise ValueError("nim.piles")
balance = 0
for pile in piles:
balance ^= pile
if balance == 0:
return None
for index, pile in enumerate(piles):
reduced = pile ^ balance
if reduced < pile:
return index, reducedThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.