quick way to get all transitions of a neighborhood

For scripts to aid with computation or simulation in cellular automata.
Post Reply
User avatar
CARuler
Posts: 1351
Joined: July 30th, 2024, 5:38 pm
Location: A rule-verse in floor rule-verse of the CGOL skyscraper

quick way to get all transitions of a neighborhood

Post by CARuler »

o is the number of orthogonal cells, d is the number of diagonal cells, q is the number of oblique cells

Code: Select all

def D4(o,d,q):
    if(o == 0):
        if(d == 0):
            if(q == 0):
                return(1)
            return(2*D4(0,0,q-1))
        return(2*D4(0,d-1,q))
    return(2*D4(o-1,d,q))
def C4(o,d,q):
    if(o == 0):
        if(d == 0):
            if(q == 0):
                return(0)
            return(4*C4(0,0,q-1)+D4(0,0,q-1))
        return(2*C4(0,d-1,q))
    return(2*C4(o-1,d,q))
def D20(o,d,q):
    if(o == 0):
        if(d == 0):
            if(q == 0):
                return(0)
            return(4*D20(0,0,q-1)+D4(0,0,q-1))
        return(2*D20(0,d-1,q))
    return(4*D20(o-1,d,q)+D4(o-1,d,q))
def D21(o,d,q):
    return(D20(d,o,q))
def C2(o,d,q):
    if(o == 0):
        if(d == 0):
            if(q == 0):
                return(0)
            return(16*C2(0,0,q-1)+6*D20(0,0,q-1)+6*D21(0,0,q-1)+4*C4(0,0,q-1)+2*D4(0,0,q-1))
        return(4*C2(0,d-1,q)+D20(0,d-1,q)+C4(0,d-1,q))
    return(4*C2(o-1,d,q)+D21(o-1,d,q)+C4(o-1,d,q))
def D10(o,d,q):
    if(o == 0):
        if(d == 0):
            if(q == 0):
                return(0)
            return(16*D10(0,0,q-1)+12*D20(0,0,q-1)+6*D4(0,0,q-1))
        return(4*D10(0,d-1,q)+2*D20(0,d-1,q)+D4(0,d-1,q))
    return(8*D10(o-1,d,q)+4*D20(o-1,d,q)+2*D4(o-1,d,q))
def D11(o,d,q):
    return(D10(d,o,q))
def C1(o,d,q):
    if(o == 0):
        if(d == 0):
            if(q == 0):
                return(0)
            return(256*C1(0,0,q-1)+120*D10(0,0,q-1)+120*D11(0,0,q-1)+120*C2(0,0,q-1)+54*D20(0,0,q-1)+54*D21(0,0,q-1)+60*C4(0,0,q-1)+24*D4(0,0,q-1))
        return(C1(d,0,q))
    return(16*C1(o-1,d,q)+6*D11(o-1,d,q)+4*D10(o-1,d,q)+6*C2(o-1,d,q)+2*D21(o-1,d,q)+D20(o-1,d,q)+3*C4(o-1,d,q))
def N(o,d,q):
    return(D4(o,d,q)+C4(o,d,q)+D20(o,d,q)+D21(o,d,q)+C2(o,d,q)+D10(o,d,q)+D11(o,d,q)+C1(o,d,q))
print("o:")
O = int(input())
print("d:")
D = int(input())
print("q:")
Q = int(input())
print(N(O,D,Q))
likes interesting rules
vist my rules here
also likes weird growth patterns in CA
hyperbolic CA!!!
ADHD user
mostly inactive
Post Reply