Created
April 4, 2018 01:42
-
-
Save javelinanddart/fb96652571b1cd2894c893bcadd2f76f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f=open("ICMAT.txt") | |
g=open("CSMAT.txt", "a") | |
matrix=[] | |
connections=[] | |
def clearmat(r,s): | |
out=[] | |
for x in range (r): | |
out.append([]) | |
for y in range (s): | |
out[x].append(0) | |
return(out) | |
def newmat(): | |
out=[] | |
while True: | |
out.append((f.readline()).split(" ")) | |
if out[len(out)-1]==["\n"]: | |
out.pop() | |
return(out) | |
out[len(out)-1][len(out[0])-1]=out[len(out)-1][len(out[0])-1][0:-1] | |
try: | |
out[len(out)-1]=[int(e) for e in out[len(out)-1]] | |
except ValueError: | |
return(0) | |
def clearthatshit(r,s): | |
for column in range (s,columns): | |
matrix[r][column]=0 | |
for row in range (r+1,rows): | |
for column in range (0,columns): | |
matrix[row][column]=0 | |
def emptycells(): | |
for column in range (columns): | |
for row in range (rows): | |
if matrix[row][column]==0: | |
return(True) | |
return(False) | |
def printmat(): | |
for row in range(rows): | |
line=str(inmatrix[row][0]*matrix[row][0]) | |
for col in range(1,columns): | |
line=line+" "+str(inmatrix[row][col]*matrix[row][col]) | |
g.write(line) | |
g.write("\n") | |
# print(line) | |
g.write("\n") | |
# print() | |
def consistentlysigned(): | |
connection=-1 | |
while connection<len(connections)-1: | |
connection=connection+1 | |
row1=connections[connection][0][0] | |
row2=connections[connection][1][0] | |
col1=connections[connection][0][1] | |
col2=connections[connection][1][1] | |
values=[0,0,0,0] | |
values[0]=matrix[row1][col1] | |
values[1]=matrix[row1][col2] | |
values[2]=matrix[row2][col1] | |
values[3]=matrix[row2][col2] | |
zeroes=0 | |
for x in values: | |
if x==0: | |
zeroes=zeroes+1 | |
if zeroes>1: | |
continue | |
elif zeroes==0: | |
if values[0]*values[1]*values[2]*values[3]==1: | |
return(False) | |
continue | |
else: | |
test=-1 | |
for v in values: | |
if v==0: | |
pass | |
else: | |
test=test*v #after this, test should have the value needed for the remaining cell: ie if values=[-1,-1,-1,0], test=1. | |
empty=values.index(0) | |
if empty==0: | |
matrix[row1][col1]=test | |
elif empty==1: | |
matrix[row1][col2]=test | |
elif empty==2: | |
matrix[row2][col1]=test | |
else: | |
matrix[row2][col2]=test | |
connection=-1 | |
continue | |
return(True) | |
def nextcell (r,s): | |
if s==columns: | |
s=0 | |
r=r+1 | |
if r==rows: | |
return() | |
if matrix[r][s]==0: | |
for n in [1,-1]: | |
matrix[r][s]=n | |
if not(consistentlysigned()): | |
clearthatshit(r,s) | |
continue | |
if not(emptycells()): | |
printmat() | |
count=count+1 | |
clearthatshit(r,s) | |
continue | |
nextcell(r,s+1) | |
clearthatshit(r,s) | |
matrix[r][s]=0 | |
else: | |
nextcell(r,s+1) | |
while True: | |
count=0 | |
inmatrix=[] | |
inmatrix=newmat() | |
if inmatrix==0: | |
break | |
rows=len(inmatrix) | |
columns=len(inmatrix[0]) | |
n=0 | |
for x in inmatrix: | |
for y in x: | |
if y>n: | |
n=y | |
print([rows,columns,n]) | |
print(inmatrix) | |
connections=[] | |
for number in range(1,n+1): | |
poslist=[] | |
for row in range(rows): | |
for column in range(columns): | |
if inmatrix[row][column]==number: | |
poslist.append([row,column]) | |
for i in range(len(poslist)): | |
for j in range(i+1,len(poslist)): | |
connections.append([poslist[i],poslist[j]]) | |
i=0 | |
while i<len(connections): | |
# print([[connections[i][0][0], connections[i][1][1]],[connections[i][1][0], connections[i][0][1]]]) | |
connections.remove([[connections[i][0][0], connections[i][1][1]],[connections[i][1][0], connections[i][0][1]]]) | |
i=i+1 | |
print(connections) | |
matrix=clearmat(rows,columns) | |
nextcell(0,0) | |
print(count) | |
asdasdasdasds=input() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f=open("ICMAT.txt") | |
g=open("CSMAT.txt", "a") | |
matrix=[] | |
connections=[] | |
def clearmat(r,s): | |
out=[] | |
for x in range (r): | |
out.append([]) | |
for y in range (s): | |
out[x].append(0) | |
return(out) | |
def newmat(): | |
out=[] | |
while True: | |
out.append((f.readline()).split(" ")) | |
if out[len(out)-1]==["\n"]: | |
out.pop() | |
return(out) | |
out[len(out)-1][len(out[0])-1]=out[len(out)-1][len(out[0])-1][0:-1] | |
try: | |
out[len(out)-1]=[int(e) for e in out[len(out)-1]] | |
except ValueError: | |
return(0) | |
def clearthatshit(r,s): | |
for column in range (s,columns): | |
matrix[r][column]=0 | |
for row in range (r+1,rows): | |
for column in range (0,columns): | |
matrix[row][column]=0 | |
def emptycells(): | |
for column in range (columns): | |
for row in range (rows): | |
if matrix[row][column]==0: | |
return(True) | |
return(False) | |
def printmat(): | |
for row in range(rows): | |
line=str(inmatrix[row][0]*matrix[row][0]) | |
for col in range(1,columns): | |
line=line+" "+str(inmatrix[row][col]*matrix[row][col]) | |
g.write(line) | |
g.write("\n") | |
# print(line) | |
g.write("\n") | |
# print() | |
def consistentlysigned(): | |
connection=-1 | |
while connection<len(connections)-1: | |
connection=connection+1 | |
row1=connections[connection][0][0] | |
row2=connections[connection][1][0] | |
col1=connections[connection][0][1] | |
col2=connections[connection][1][1] | |
values=[0,0,0,0] | |
values[0]=matrix[row1][col1] | |
values[1]=matrix[row1][col2] | |
values[2]=matrix[row2][col1] | |
values[3]=matrix[row2][col2] | |
zeroes=0 | |
for x in values: | |
if x==0: | |
zeroes=zeroes+1 | |
if zeroes>1: | |
continue | |
elif zeroes==0: | |
if values[0]*values[1]*values[2]*values[3]==1: | |
return(False) | |
continue | |
else: | |
test=-1 | |
for v in values: | |
if v==0: | |
pass | |
else: | |
test=test*v #after this, test should have the value needed for the remaining cell: ie if values=[-1,-1,-1,0], test=1. | |
empty=values.index(0) | |
if empty==0: | |
matrix[row1][col1]=test | |
elif empty==1: | |
matrix[row1][col2]=test | |
elif empty==2: | |
matrix[row2][col1]=test | |
else: | |
matrix[row2][col2]=test | |
connection=-1 | |
continue | |
return(True) | |
def nextcell (r,s): | |
if s==columns: | |
s=0 | |
r=r+1 | |
if r==rows: | |
return() | |
if matrix[r][s]==0: | |
for n in [1,-1]: | |
matrix[r][s]=n | |
if not(consistentlysigned()): | |
clearthatshit(r,s) | |
continue | |
if not(emptycells()): | |
printmat() | |
clearthatshit(r,s) | |
continue | |
nextcell(r,s+1) | |
clearthatshit(r,s) | |
matrix[r][s]=0 | |
else: | |
nextcell(r,s+1) | |
while True: | |
inmatrix=[] | |
inmatrix=newmat() | |
if inmatrix==0: | |
break | |
rows=len(inmatrix) | |
columns=len(inmatrix[0]) | |
n=0 | |
for x in inmatrix: | |
for y in x: | |
if y>n: | |
n=y | |
print([rows,columns,n]) | |
print(inmatrix) | |
connections=[] | |
for number in range(1,n+1): | |
poslist=[] | |
for row in range(rows): | |
for column in range(columns): | |
if inmatrix[row][column]==number: | |
poslist.append([row,column]) | |
for i in range(len(poslist)): | |
for j in range(i+1,len(poslist)): | |
connections.append([poslist[i],poslist[j]]) | |
i=0 | |
while i<len(connections): | |
# print([[connections[i][0][0], connections[i][1][1]],[connections[i][1][0], connections[i][0][1]]]) | |
connections.remove([[connections[i][0][0], connections[i][1][1]],[connections[i][1][0], connections[i][0][1]]]) | |
i=i+1 | |
print(connections) | |
matrix=clearmat(rows,columns) | |
nextcell(0,0) | |
asdasdasdasds=input() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 2 3 | |
2 1 4 | |
3 4 1 | |
1 2 3 | |
2 1 4 | |
4 3 2 | |
1 2 3 | |
3 4 1 | |
2 1 4 | |
1 2 3 | |
3 4 1 | |
4 3 2 | |
1 2 3 | |
4 3 2 | |
2 1 4 | |
1 2 3 | |
4 3 2 | |
3 4 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment