1-9数字填入 使横 竖 斜 方向的 数字相加都得15
-
#!/usr/bin/env pythgon
-
# -*- coding:utf-8 -*-
-
-
import itertools
-
-
TEST_DATA = 15
-
BIAOZHENG = range(1,10,1)
-
-
def check_line(line_num=0):
-
temp_data = ready_return_array[line_num*3+0]+ready_return_array[line_num*3+1]+ready_return_array[line_num*3+2]
-
if temp_data != TEST_DATA:
-
return False
-
return True
-
def check_all_lines():
-
if check_line(0) and check_line(1) and check_line(2):
-
return True
-
else:
-
return False
-
-
-
-
-
def check_raw(raw_num=0):
-
-
temp_data = ready_return_array[raw_num]+ready_return_array[raw_num+3]+ready_return_array[raw_num+6]
-
if temp_data != TEST_DATA:
-
return False
-
return True
-
-
def check_all_raws():
-
if check_raw(0) and check_raw(1) and check_raw(2):
-
return True
-
else:
-
return False
-
-
def check_bias():
-
temp_data = ready_return_array[0] + ready_return_array[4] + ready_return_array[8]
-
if temp_data != TEST_DATA:
-
return False
-
temp_data = ready_return_array[2]+ready_return_array[4]+ready_return_array[6]
-
if temp_data != TEST_DATA:
-
return False
-
return True
-
-
-
-
-
LIST_NAME = r'E:\study\src\src\list.txt'
-
-
-
-
# 2,9,4,7,5,3,6,1,8
-
if __name__ == '__main__':
-
# king(6,2)
-
temp_data = []
-
answer_question=[]
-
print BIAOZHENG
-
# handle = open(LIST_NAME,'w')
-
# temp = itertools.permutations(BIAOZHENG)
-
# temp_data = list(temp)
-
# handle.write(str(temp_data))
-
# handle.close()
-
temp = itertools.permutations(BIAOZHENG)
-
temp_data = list(temp)
-
print 'the len is =',len(temp_data)
-
for i in xrange(len(temp_data)):
-
# print temp_data[i]
-
ready_return_array = list(temp_data[i])
-
# print ready_return_array
-
if check_bias() and check_all_raws() and check_all_lines():
-
print ready_return_array
-
answer_question.append(ready_return_array)
-
# break
-
-
print answer_question
-
#!/usr/bin/env pythgon
-
# -*- coding:utf-8 -*-
-
-
import itertools
-
-
TEST_DATA = 15
-
BIAOZHENG = range(1,10,1)
-
-
def check_line(line_num=0):
-
temp_data = ready_return_array[line_num*3+0]+ready_return_array[line_num*3+1]+ready_return_array[line_num*3+2]
-
if temp_data != TEST_DATA:
-
return False
-
return True
-
def check_all_lines():
-
if check_line(0) and check_line(1) and check_line(2):
-
return True
-
else:
-
return False
-
-
-
-
-
def check_raw(raw_num=0):
-
-
temp_data = ready_return_array[raw_num]+ready_return_array[raw_num+3]+ready_return_array[raw_num+6]
-
if temp_data != TEST_DATA:
-
return False
-
return True
-
-
def check_all_raws():
-
if check_raw(0) and check_raw(1) and check_raw(2):
-
return True
-
else:
-
return False
-
-
def check_bias():
-
temp_data = ready_return_array[0] + ready_return_array[4] + ready_return_array[8]
-
if temp_data != TEST_DATA:
-
return False
-
temp_data = ready_return_array[2]+ready_return_array[4]+ready_return_array[6]
-
if temp_data != TEST_DATA:
-
return False
-
return True
-
-
-
-
-
LIST_NAME = r'E:\study\src\src\list.txt'
-
-
-
-
# 2,9,4,7,5,3,6,1,8
-
if __name__ == '__main__':
-
# king(6,2)
-
temp_data = []
-
answer_question=[]
-
print BIAOZHENG
-
# handle = open(LIST_NAME,'w')
-
# temp = itertools.permutations(BIAOZHENG)
-
# temp_data = list(temp)
-
# handle.write(str(temp_data))
-
# handle.close()
-
temp = itertools.permutations(BIAOZHENG)
-
temp_data = list(temp)
-
print 'the len is =',len(temp_data)
-
for i in xrange(len(temp_data)):
-
# print temp_data[i]
-
ready_return_array = list(temp_data[i])
-
# print ready_return_array
-
if check_bias() and check_all_raws() and check_all_lines():
-
print ready_return_array
-
answer_question.append(ready_return_array)
-
# break
-
-
print answer_question
阅读(2884) | 评论(0) | 转发(0) |