Open the context
Choose the project folder and name the files or behavior involved.
Compute one synchronous step of an elementary cellular automaton on a ring of one through 256 binary cells. Check wraparound neighbors and a single cell, rejecting empty input, Boolean cells and rules outside zero through 255.
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 cellular_step(bits, rule):
bits = tuple(bits)
if not 1 <= len(bits) <= 256 or any(type(v) is not int or v not in (0, 1) for v in bits):
raise ValueError("cells.binary")
if type(rule) is not int or not 0 <= rule <= 255:
raise ValueError("rule.byte")
n = len(bits)
return [(rule >> (4 * bits[(i - 1) % n] + 2 * bits[i] + bits[(i + 1) % n])) & 1 for i in range(n)]The 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.