# -*- coding: utf-8 -*- """ Created on Mon Dec 26 19:24:25 2016 @author: Yichen """ import numpy class FoundException(Exception): pass def mutate(raw_data): mutated_data=[[],[],[],[]] #raw_data 4x4 temp_data=[] #First consider 4 sides for i in range(4): temp_data=[raw_data[(i)%4],raw_data[(i+1)%4],raw_data[(i+2)%4],raw_data[(i+3)%4]] mutated_data[i]=temp_data #Next condider 2 sides (up and down) mutated_data2=[[],[],[],[]] temp_data=[] raw_data_temp=raw_data[::-1] re_raw_data=[raw_data_temp[0][::-1],raw_data_temp[1][::-1],raw_data_temp[2][::-1],raw_data_temp[3][::-1]] for i in range(4): temp_data=[re_raw_data[(i)%4],re_raw_data[(i+1)%4],re_raw_data[(i+2)%4],re_raw_data[(i+3)%4]] mutated_data2[i]=temp_data #Combine mutated_data[0:0]=mutated_data2 return mutated_data if __name__ == '__main__': raw1=[[1,1,1,1],[0,0,0,0],[0,0,0,0],[1,0,0,1]] raw2=[[1,1,1,1],[1,0,0,1],[0,0,0,0],[1,1,0,0]] raw3=[[1,1,1,1],[0,0,0,0],[0,0,0,0],[1,0,1,1]] raw4=[[1,1,1,1],[0,0,1,0],[0,0,1,0],[1,1,1,1]] raw5=[[1,1,1,1],[1,1,0,0],[1,0,0,0],[1,0,0,1]] raw6=[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]] result1=mutate(numpy.array(raw1)) result2=mutate(numpy.array(raw2)) result3=mutate(numpy.array(raw3)) result4=mutate(numpy.array(raw4)) result5=mutate(numpy.array(raw5)) result6=mutate(numpy.array(raw6)) result1[0:0]=result2 result1[0:0]=result3 result1[0:0]=result4 result1[0:0]=result5 result1[0:0]=result6 result=result1 #position1 position1=[] for j in range(48): #loop on 48 possible pattern temp=numpy.zeros([4,4,4]) for i in range(4): #data recording temp[2][3-i][1]=result[j][0][i] temp[2][3-i][2]=result[j][1][i] temp[3][3-i][2]=result[j][2][i] temp[3][3-i][1]=result[j][3][i] position1[0:0]=[temp] #position1=numpy.array(position1) #position2 position2=[] for j in range(48): #loop on 48 possible pattern temp=numpy.zeros([4,4,4]) for i in range(4): #data recording temp[0][3-i][1]=result[j][0][i] temp[0][3-i][2]=result[j][1][i] temp[1][3-i][2]=result[j][2][i] temp[1][3-i][1]=result[j][3][i] position2[0:0]=[temp] #position2=numpy.array(position1) #position3 position3=[] for j in range(48): #loop on 48 possible pattern temp=numpy.zeros([4,4,4]) for i in range(4): #data recording temp[i][1][2]=result[j][0][i] temp[i][1][3]=result[j][1][i] temp[i][2][3]=result[j][2][i] temp[i][2][2]=result[j][3][i] position3[0:0]=[temp] #position3=numpy.array(position3) #position4 position4=[] for j in range(48): #loop on 48 possible pattern temp=numpy.zeros([4,4,4]) for i in range(4): #data recording temp[i][1][0]=result[j][0][i] temp[i][1][1]=result[j][1][i] temp[i][2][1]=result[j][2][i] temp[i][2][0]=result[j][3][i] position4[0:0]=[temp] #position4=numpy.array(position4) #position5 position5=[] for j in range(48): #loop on 48 possible pattern temp=numpy.zeros([4,4,4]) for i in range(4): #data recording temp[1][1][3-i]=result[j][0][i] temp[1][0][3-i]=result[j][1][i] temp[2][0][3-i]=result[j][2][i] temp[2][1][3-i]=result[j][3][i] position5[0:0]=[temp] #position5=numpy.array(position5) #position6 position6=[] for j in range(48): #loop on 48 possible pattern temp=numpy.zeros([4,4,4]) for i in range(4): #data recording temp[1][3][3-i]=result[j][0][i] temp[1][2][3-i]=result[j][1][i] temp[2][2][3-i]=result[j][2][i] temp[2][3][3-i]=result[j][3][i] position6[0:0]=[temp] #position6=numpy.array(position6) count=0 count2=0 try: #final loop for k1 in range(8): #print('k1='+ str(k1)) for k2 in range(8,48): for k3 in range(8,48): if k2/8==k3/8: continue for k4 in range(8,48): if k2/8==k4/8 or k3/8==k4/8: continue for k5 in range(8,48): if k2/8==k5/8 or k3/8==k5/8 or k4/8==k5/8: continue for k6 in range(8,48): if k2/8==k6/8 or k3/8==k6/8 or k4/8==k6/8 or k5/8==k6/8: continue total_position=[] total_position = position1[k1]+position2[k2]+position3[k3]+position4[k4]+position5[k5]+position6[k6] #total_position=numpy.array(total_position) if total_position.sum()!=56: raise FoundException() if total_position.max()==1: print ('find it:') print position1[k1] print position2[k2] print position3[k3] print position4[k4] print position5[k5] print position6[k6] raise FoundException() except FoundException: print ('done') ''' Solution: Position 1: [[ 0. 1. 1. 0.] [ 0. 1. 0. 0.] [ 0. 1. 0. 0.] [ 0. 1. 1. 0.]]] Position 2: [[ 0. 1. 1. 0.] [ 0. 1. 0. 0.] [ 0. 1. 0. 0.] [ 0. 1. 1. 0.]] [[ 0. 1. 1. 0.] [ 0. 1. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.]] Position 3: [[ 0. 0. 0. 0.] [ 0. 0. 1. 1.] [ 0. 0. 1. 1.] [ 0. 0. 0. 0.]] [[ 0. 0. 0. 0.] [ 0. 0. 1. 1.] [ 0. 0. 1. 1.] [ 0. 0. 0. 0.]] [[ 0. 0. 0. 0.] [ 0. 0. 1. 1.] [ 0. 0. 1. 1.] [ 0. 0. 0. 0.]] [[ 0. 0. 0. 0.] [ 0. 0. 1. 1.] [ 0. 0. 1. 1.] [ 0. 0. 0. 0.]]] Position 4: [[[ 0. 0. 0. 0.] [ 1. 0. 0. 0.] [ 1. 0. 0. 0.] [ 0. 0. 0. 0.]] [[ 0. 0. 0. 0.] [ 1. 0. 0. 0.] [ 1. 0. 0. 0.] [ 0. 0. 0. 0.]] [[ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 1. 0. 0. 0.] [ 0. 0. 0. 0.]] [[ 0. 0. 0. 0.] [ 1. 0. 0. 0.] [ 1. 0. 0. 0.] [ 0. 0. 0. 0.]]] Position 5: [[[ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.]] [[ 1. 0. 0. 1.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.]] [[ 1. 1. 1. 1.] [ 1. 1. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.]] [[ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.]]] Position 6: [[[ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.]] [[ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 1. 0. 0.] [ 1. 1. 1. 1.]] [[ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 1. 0. 0.] [ 1. 1. 1. 1.]] [[ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.]]] '''
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question