#Harmony Calculation for dichotomy level reinin structures
#Cell Index for excel
#Input needs to be in a single column, in the order:
#E, N, T, P, EN, ET, EP, NT, NP, TP, ENT, ENP, ETP, NTP, ENTP
#Starting at cell F2 for dichotomy E
startColumn = 'F'
startRow = 2
#Assign variables to excel input cells, in vector numerical order
P= startColumn+str(startRow+ 3) #0001
T= startColumn+str(startRow+ 2) #0010
TP= startColumn+str(startRow+ 9) #0011
N= startColumn+str(startRow+ 1) #0100
NP= startColumn+str(startRow+ 8) #0101
NT= startColumn+str(startRow+ 7) #0110
NTP= startColumn+str(startRow+13) #0111
E= startColumn+str(startRow+ 0) #1000
EP= startColumn+str(startRow+ 6) #1001
ET= startColumn+str(startRow+ 5) #1010
ETP= startColumn+str(startRow+12) #1011
EN= startColumn+str(startRow+ 4) #1100
ENP= startColumn+str(startRow+11) #1101
ENT= startColumn+str(startRow+10) #1110
ENTP=startColumn+str(startRow+14) #1111
#Dichotomy vectors put in list in numerical order
cellList = ['IDENTITY',P,T,TP,N,NP,NT,NTP,E,EP,ET,ETP,EN,ENP,E NT,ENTP]
#Dichotomy variable from index number
nameList = ['IDENTITY','P','T','TP','N','NP','NT','NTP','E','E P','ET','ETP','EN','ENP','ENT','ENTP']
#List Index
list1= [''] #0000
listP= [''] #0001
listT= [''] #0010
listTP= [''] #0011
listN= [''] #0100
listNP= [''] #0101
listNT= [''] #0110
listNTP= [''] #0111
listE= [''] #1000
listEP= [''] #1001
listET= [''] #1010
listETP= [''] #1011
listEN= [''] #1100
listENP= [''] #1101
listENT= [''] #1110
listENTP= [''] #1111
listList =
[list1,listP,listT,listTP,listN,listNP,listNT,listN TP,listE,listEP,listET,listETP,listEN,listENP,list ENT,listENTP]
#FUNCTIONS
#Print list items with line space at end
def printList(arg1):
i = 0
loop=len(arg1)
while (i < loop):
print(arg1[i])
i = i + 1
print ("")
#Add new item to bottom of list
def addLast(item,list):
list.insert(len(list),item)
#vector addition for two dichotomy vectors strings
def vectorAdd (v1,v2):
v1=str(v1)
v2=str(v2)
a=( int(v1[0]) + int(v2[0]) )%2 #Mod 2 addition, 1+0=1 1+1=0
b=( int(v1[1]) + int(v2[1]) )%2
c=( int(v1[2]) + int(v2[2]) )%2
d=( int(v1[3]) + int(v2[3]) )%2
v3=str(a)+str(b)+str(c)+str(d) #Recontructs output vector string
return(v3)
#Converts boolean vector to decimal equivelent to use with list indexing
def vectorToInt (vector):
vector=str(vector)
a=int(vector[0])*8+int(vector[1])*4+int(vector[2])*2+int(vector[3])
return a
#Converts a number 0-15 into a vector string
def intToVector (integer):
integer = ''.join(str(1 & int(integer) >> i) for i in range(4)[::-1])
return integer
#Adds two integers as if they were vectors and returns an integer
def intAdd (int1, int2):
int1 = intToVector(int1)
int2 = intToVector(int2)
int3 = vectorAdd(int1,int2)
int3 = vectorToInt(int3)
return int3
#PROGRAM
#Small group level constructions, 7 for each dichotomy
w=1
while (w<16):
vw=intToVector(w) #w as a vector
x=w+1
while (x<16):
vx=intToVector(x) #x as a vector
if vw!=vx:
formula = '='+cellList[w]+'*'+cellList[x]
location = listList[vectorToInt(vectorAdd(vw,vx))]
addLast( formula, location)
x=x+1
w=w+1
#Dyad level constructions, 28 for each dichotomy
w=1
while (w<16):
vw=intToVector(w) #w as a vector
x=w+1
while (x<16):
vx=intToVector(x) #x as a vector
if w!=x:
y=x+1
while (y<16):
vy=intToVector(y) #y as a vector
if vectorAdd(vw,vx)!=vy:
formula = '='+cellList[w]+'*'+cellList[x]+'*'+cellList[y]
location = listList[vectorToInt(vectorAdd(vectorAdd(vw,vx),vy))]
addLast( formula, location)
y=y+1
x=x+1
w=w+1
#Type level constructions, 56 for each dichotomy
w=1
while (w<16):
vw=intToVector(w) #w as a vector
x=w+1
while (x<16):
vx=intToVector(x) #x as a vector
if w!=x:
y=x+1
while (y<16):
vy=intToVector(y) #y as a vector
if vectorAdd(vw,vx)!=vy and vw!=vy and vx!=vy:
z=y+1
while (z<16):
vv1=vw
vv2=vx
vv3=vy
vv4=vectorAdd(vw,vx)
vv5=vectorAdd(vw,vy)
vv6=vectorAdd(vx,vy)
vv7=vectorAdd(vectorAdd(vw,vx),vy)
vz=intToVector(z) #z as a vector
if (vz!=vv1) and (vz!=vv2) and (vz!=vv3) and (vz!=vv4) and (vz!=vv5) and (vz!=vv6) and (vz!=vv7):
formula = '='+cellList[w]+'*'+cellList[x]+'*'+cellList[y]+'*'+cellList[z]
location = listList[vectorToInt(vectorAdd(vectorAdd(vectorAdd(vw,vx),v y),vz))]
addLast( formula, location)
z=z+1
y=y+1
x=x+1
w=w+1
#PRINT RESULTS
#In vector numerical order, to be copied into Excel
i=1
while i<16:
vectorNum = i
print(nameList[vectorNum])
printList(listList[vectorNum])
print('--------------------')
print('')
i=i+1
#END PROGRAM