from bitarray import bitarray from random import getrandbits import pygame from pygame.locals import * import numpy as np def step(mem): two03 = ~mem[0] & ~mem[1] & mem[2] & ~mem[3]& ~mem[4] & mem[5] two14 = mem[0] & ~mem[1] & ~mem[2] & mem[3]& ~mem[4]& ~mem[5] two25 = ~mem[0] & mem[1] & ~mem[2] & ~mem[3]& mem[4]& ~mem[5] three024 = ~mem[0] & mem[1] & ~mem[2] & mem[3] & ~mem[4]& mem[5] three135 = mem[0] & ~mem[1] & mem[2] & ~mem[3] & mem[4]& ~mem[5] mem[0] = (mem[0] & ~three135 & ~two14) | two03 | three024 mem[1] = (mem[1] & ~three024 & ~two25) | two14 | three135 mem[2] = (mem[2] & ~three135 & ~two03) | two25 | three024 mem[3] = (mem[3] & ~three024 & ~two14) | two03 | three135 mem[4] = (mem[4] & ~three135 & ~two25) | two14 | three024 mem[5] = (mem[5] & ~three024 & ~two03) | two25 | three135 mem[0] = cyclical_right_shift(mem[0],w) mem[1] = cyclical_right_shift(mem[1],w-1) mem[2] = cyclical_left_shift(mem[2],1) mem[3] = cyclical_left_shift(mem[3],w) mem[4] = cyclical_left_shift(mem[4],w-1) mem[5] = cyclical_right_shift(mem[5],1) def cyclical_right_shift(bs, i): mask = 2**i-1 carry = bs & mask slide = bs & ~mask return (carry << (l-i)) | (slide>>i) def cyclical_left_shift(bs, i): mask = 2**(l-i) -1 carry = bs & ~mask slide = bs & mask return (carry >> (l-i)) | (slide<